Re: "min" and "max"

2022-08-09 Thread jfondren via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 00:03:37 UTC, pascal111 wrote: On Tuesday, 9 August 2022 at 23:56:53 UTC, Paul Backus wrote: On Tuesday, 9 August 2022 at 23:35:23 UTC, pascal111 wrote: "min" and "max" in "std.algorithm" can be used with single values to pick up the min and max values, but it di

Re: Verbosity in D

2022-08-07 Thread jfondren via Digitalmars-d-learn
On Sunday, 7 August 2022 at 16:01:08 UTC, pascal111 wrote: It's clear by working with D that it has the same bad point like Pascal language; the "verbosity". Is there any plans in future to make some shorthanded techniques that clean verbosity from D? That's not clear to me at all, and your P

Re: Unittest Absurdity

2022-08-04 Thread jfondren via Digitalmars-d-learn
On Friday, 5 August 2022 at 02:20:31 UTC, Steven Schveighoffer wrote: On 8/4/22 9:51 PM, Paul Backus wrote: Another option: use -vcg-ast, and have the compiler tell you what it's actually calling. It's not ignoring that line, it's just not doing what you think it's doing. The output's not tha

Re: Unittest Absurdity

2022-08-04 Thread jfondren via Digitalmars-d-learn
On Friday, 5 August 2022 at 01:53:42 UTC, Ruby The Roobster wrote: On Friday, 5 August 2022 at 01:38:48 UTC, jfondren wrote: Here's a complete example that passes tests: ```d struct S { int n; void opOpAssign(string op)(S rhs) if (op == "/") { n++; } } Nevermind. I have t

Re: Unittest Absurdity

2022-08-04 Thread jfondren via Digitalmars-d-learn
On Friday, 5 August 2022 at 01:38:48 UTC, jfondren wrote: Here's a complete example that passes tests: ```d struct S { int n; void opOpAssign(string op)(S rhs) if (op == "/") { n++; } } unittest { auto a = S(1), b = S(2); a /= b; b /= a; assert(a.n == 2);

Re: Unittest Absurdity

2022-08-04 Thread jfondren via Digitalmars-d-learn
On Friday, 5 August 2022 at 01:25:50 UTC, Ruby The Roobster wrote: On Friday, 5 August 2022 at 01:23:40 UTC, Ruby The Roobster wrote: [SNIP] Any function other than an operator overload seems to work fine. Also, this isn't mentioned in the spec. Additional Information: Fails for both DMD an

Re: Obsecure problem 2

2022-08-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 19:11:51 UTC, pascal111 wrote: On Wednesday, 3 August 2022 at 18:53:35 UTC, jfondren wrote: On Wednesday, 3 August 2022 at 18:33:37 UTC, pascal111 wrote: I changed it to "x=notfunny(x);" and has the same result. Now you are changing the value of the temporary lo

Re: Obsecure problem 2

2022-08-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 18:33:37 UTC, pascal111 wrote: I changed it to "x=notfunny(x);" and has the same result. Now you are changing the value of the temporary loop variable that is still immediately discarded afterwards. You should return a new range that has the values you want, no

Re: Obsecure problem 2

2022-08-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 17:33:40 UTC, pascal111 wrote: On Wednesday, 3 August 2022 at 17:09:11 UTC, jfondren wrote: On Wednesday, 3 August 2022 at 16:59:53 UTC, pascal111 wrote: I tried to make a template that receive lambda expression to apply it on a given range the user specifies, but

Re: Obsecure problem 2

2022-08-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 August 2022 at 16:59:53 UTC, pascal111 wrote: I tried to make a template that receive lambda expression to apply it on a given range the user specifies, but I found non-understood problem: Compare with: ```D auto foo(Range)(Range range) { // remove isInputRange!T test ...

Re: Choosing the correct compiler version

2022-07-19 Thread jfondren via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 15:33:59 UTC, Alexander Zhirov wrote: On Tuesday, 19 July 2022 at 15:28:44 UTC, Alexander Zhirov wrote: I'm trying to install dmd with my hands in order to build ldc2 from the sources, but I can't: I need to build a compiler under x32 in order to compile a program

Re: How to obtain Variant underlying type?

2022-07-10 Thread jfondren via Digitalmars-d-learn
On Monday, 11 July 2022 at 03:17:33 UTC, anonymouse wrote: On Sunday, 10 July 2022 at 18:31:46 UTC, drug007 wrote: I'd like to say that using of exception to break loop is really bad. Exception is exceptional thing but in the case above the exception is ordinary completion of the loop happens

Re: How to obtain Variant underlying type?

2022-07-09 Thread jfondren via Digitalmars-d-learn
On Saturday, 9 July 2022 at 23:04:20 UTC, anonymouse wrote: On Saturday, 9 July 2022 at 14:46:36 UTC, Adam D Ruppe wrote: Impossible; Variant's type is only known at runtime, and this would require compile time knowledge. Hmmm. Okay, thanks. What I really need to know is how many dimensions

Re: why there is a [] at the end of assocArray

2022-01-19 Thread jfondren via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 14:06:45 UTC, michaelbi wrote: i got it, though i still don't know where the [] come from. $ rdmd --eval 'writeln("".array.strip.sort.group.assocArray)' [] $ rdmd --eval 'writeln(typeid("".array.strip.sort.group.assocArray))' uint[dchar] It's what an empty AA

Re: Incomplete words read from file

2021-11-17 Thread jfondren via Digitalmars-d-learn
On Thursday, 18 November 2021 at 01:21:00 UTC, pascal111 wrote: I fixed the code like this and it worked without breaking words, but this time it shows single lines as if the normal context is a poem. Can we fix this or the terminal will force us and make wrapping for lines? "https://i.postim

Re: Incomplete words read from file

2021-11-17 Thread jfondren via Digitalmars-d-learn
On Wednesday, 17 November 2021 at 23:46:15 UTC, pascal111 wrote: I made small program that shows the content of textual files, and it succeeded to show non-English (Ascii code) language, but in many lines some words are not complete and their rests are in next lines, how can fix it? there's n

Re: Data conversion

2021-11-16 Thread jfondren via Digitalmars-d-learn
On Tuesday, 16 November 2021 at 19:18:50 UTC, pascal111 wrote: I used "to" keyword which "std.conv" includes for data conversions, but I think that there are some other ways for data conversions, or maybe there are common ways like casting, I hope to know about. For example, next program are us

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-08 Thread jfondren via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 02:41:18 UTC, jfondren wrote: The expectation is probably that `f.move` set `f` to `Foo.init`, but the docs say: Posted too fast. Foo qualifies with its @disable: ```d struct A { int x; } struct B { int x; @disable this(this); } unittest { import core.lifeti

Re: auto ref function parameter causes that non copyable struct is copied?

2021-11-08 Thread jfondren via Digitalmars-d-learn
On Tuesday, 9 November 2021 at 02:19:28 UTC, Stanislav Blinov wrote: On Monday, 8 November 2021 at 23:26:39 UTC, tchaloupka wrote: ``` auto gen() { Foo f; // <--- this one f.n = 42; return value(f.move()); } void main() { Foo f; f = gen().unwrap.move; } ``

Re: dmd 2.098.0: version `GLIBC_2.14' not found (required by linux/bin64/dmd)

2021-11-08 Thread jfondren via Digitalmars-d-learn
On Monday, 8 November 2021 at 23:55:02 UTC, kdevel wrote: In previous versions I used the linux32/dmd with the -m64 switch in order to generate 64-bit code. But this does not work anymore: $ linux/bin32/dmd linux/bin32/dmd: /lib/libc.so.6: version `GLIBC_2.28' not found (required by linux/

Re: Problem using struct with copy constructor with betterC

2021-11-06 Thread jfondren via Digitalmars-d-learn
On Saturday, 6 November 2021 at 17:24:07 UTC, tchaloupka wrote: When built with `-betterC` switch (dmd as ldc2 works with it). I get just: ``` Error: `TypeInfo` cannot be used with -betterC ``` Well imagine getting this useful info in a large codebase :/ Looks like https://issues.dlang.org/sh

Re: Completing C code with D style

2021-11-06 Thread jfondren via Digitalmars-d-learn
On Saturday, 6 November 2021 at 13:27:55 UTC, kdevel wrote: On Thursday, 4 November 2021 at 00:53:11 UTC, jfondren wrote: On Wednesday, 3 November 2021 at 20:36:08 UTC, russhy wrote: Keeping things simple helps debugging! I'd still have to run your program to be sure of its simple logic, tho

Re: Using "strcpy" to assign value to dynamic char array

2021-11-03 Thread jfondren via Digitalmars-d-learn
On Monday, 1 November 2021 at 19:56:13 UTC, pascal111 wrote: But what if I want to use "strcpy" function to assign that new value to the array that the problem is that the array won't take more than its first initializing value length: { char[] s="xyz".dup; strcpy(&s[0], "Hello World!"); wr

Re: Completing C code with D style

2021-11-03 Thread jfondren via Digitalmars-d-learn
On Wednesday, 3 November 2021 at 20:36:08 UTC, russhy wrote: Keeping things simple helps debugging! I'd still have to run your program to be sure of its simple logic, though. The real star d feature that would help with debugging is unittest: ```d enum sign { negatives = 'n', positives = 'p

Re: Are there anything like leetcode.com but that supports D?

2021-10-24 Thread jfondren via Digitalmars-d-learn
On Sunday, 24 October 2021 at 14:14:48 UTC, Imperatorn wrote: On Sunday, 24 October 2021 at 05:46:48 UTC, Dr Machine Code wrote: I'd like that to some friends getting start with programming. Sadly that platform doesn't support D. May I ask what platform? It's in the subject: leetcode.com

Re: Possible runtime bug in preprocessing of command line arguments passed to the D main

2021-10-24 Thread jfondren via Digitalmars-d-learn
On Sunday, 24 October 2021 at 14:21:52 UTC, Basile B. wrote: What do you think ? I'm very surprised that this is even allowed. Apparently it's Linux userspace that normally complains about it: https://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/progname.c#n54 The manpages just say ```

Re: Are there anything like leetcode.com but that supports D?

2021-10-24 Thread jfondren via Digitalmars-d-learn
On Sunday, 24 October 2021 at 05:46:48 UTC, Dr Machine Code wrote: I'd like that to some friends getting start with programming. Sadly that platform doesn't support D. Here are a few: https://www.codingame.com/ https://www.spoj.com/ https://www.hackerrank.com/

Re: Dub failing to use the linker correctly.

2021-10-22 Thread jfondren via Digitalmars-d-learn
On Friday, 22 October 2021 at 19:56:37 UTC, Ruby The Roobster wrote: I have a simple vibe-d project built with dub. Running the command, dub build --force returns the following output: I'd start by running `dub -v build --force` instead, to see the exact commands that dub is running.

Re: Can we use "ImportC" used yet?

2021-10-21 Thread jfondren via Digitalmars-d-learn
On Thursday, 21 October 2021 at 22:23:50 UTC, data pulverizer wrote: Hi, I'm getting an odd issue with ImportC when I import a header converted with `gcc -E -P ...` some of the types signatures in functions don't come through with their proper names but as `__tagXX` where `XX` is some number.

Re: Casting between structs of the same size is treated as a bit cast?

2021-10-19 Thread jfondren via Digitalmars-d-learn
On Wednesday, 20 October 2021 at 04:14:37 UTC, Dave P. wrote: I am confused on how casting structs works. According to point 9 of https://dlang.org/spec/expression.html#CastExpression: Casting a value v to a struct S, when value is not a struct of the same type, is equivalent to: ```d S(v) `

Re: std.format doesn't want to work

2021-10-17 Thread jfondren via Digitalmars-d-learn
On Sunday, 17 October 2021 at 12:53:07 UTC, solidstate1991 wrote: On Sunday, 17 October 2021 at 05:22:17 UTC, russhy wrote: On Saturday, 16 October 2021 at 22:47:09 UTC, solidstate1991 wrote: When I make this call ``` format(" %3.3f"w, avgFPS); ``` my program immediately crashes with an access

Re: Can we use "ImportC" used yet?

2021-10-16 Thread jfondren via Digitalmars-d-learn
On Sunday, 17 October 2021 at 03:38:43 UTC, data pulverizer wrote: 2. Run the commands: ``` gcc -E -P test_og.c > test_c.c dmd test.d test_c.c && ./test ``` which works. Now I've tried the same thing with library `fftw3` and getting: ``` Error: undefined identifier `__float128` ``` Which I

Re: Can we use "ImportC" used yet?

2021-10-16 Thread jfondren via Digitalmars-d-learn
On Sunday, 17 October 2021 at 02:45:03 UTC, data pulverizer wrote: While we're on this subject, I've been having similar issues now tried compiling @rempas's example file with: ``` gcc test_og.c -c -o test_og.o dmd test.d test_og.o ``` and get the response: ``` test_og.c(1): Error: identifier

Re: Can we use "ImportC" used yet?

2021-10-16 Thread jfondren via Digitalmars-d-learn
On Saturday, 16 October 2021 at 08:19:41 UTC, rempas wrote: On Saturday, 16 October 2021 at 07:09:16 UTC, jfondren wrote: This test_og.c works (while obviously breaking some bswap functions): I don't know if I should have known that but what is "bswap"? I came up with those `#define`s by l

Re: Can we use "ImportC" used yet?

2021-10-16 Thread jfondren via Digitalmars-d-learn
On Saturday, 16 October 2021 at 06:39:46 UTC, rempas wrote: ``` // Filename: test.d import test_c; void main() { hello_world(); } // Filename: test_og.c #include #include void hello_world() { puts("Hello world!!!"); } ``` After that, I'm using: `gcc -E -P test_og.c > test_c.c` to prepr

Re: How to make a function that accepts optional struct but can accept struct literal too

2021-10-15 Thread jfondren via Digitalmars-d-learn
On Friday, 15 October 2021 at 20:33:33 UTC, JN wrote: Is there some nice way of achieving something like this C99 code in D? option 1: use an intermediate lambda: ```d import std.stdio; struct inputs_t { int x, y; } // no ; needed here void foo(inputs_t* optional_inputs) { if (!optio

Re: Can we use "ImportC" used yet?

2021-10-15 Thread jfondren via Digitalmars-d-learn
On Friday, 15 October 2021 at 20:45:35 UTC, jfondren wrote: ``` 0 stat(27, 11, 1, 8592, 1000, 5, 0, 34824, 0, 1024, 0, timespec(1634329152, 581807916), timespec(1634329152, 581807916), timespec(1634272061, 581807916), [0, 0, 0]) 9 ``` the d programmer did not have to carefully `extern (C)` an

Re: Can we use "ImportC" used yet?

2021-10-15 Thread jfondren via Digitalmars-d-learn
On Friday, 15 October 2021 at 18:39:10 UTC, rempas wrote: Cause I can't find an option in the latest DMD release and because the ImportC [page](https://dlang.org/spec/importc.html#importing) seems to be incomplete (even saying it's under construct), I'm wondering if ImportC exists even as prot

Re: Threading challenge: calculate fib(45) while spinning

2021-10-14 Thread jfondren via Digitalmars-d-learn
On Friday, 15 October 2021 at 03:54:17 UTC, Ali Çehreli wrote: On 10/14/21 8:35 PM, jfondren wrote: The book, "The Go Programming Language" has this simple goroutine example: Here is one that uses receiveTimeout and OwnerTerminated: Very nice, replacing Thread.sleep with receiveTimeout and

Threading challenge: calculate fib(45) while spinning

2021-10-14 Thread jfondren via Digitalmars-d-learn
The book, "The Go Programming Language" has this simple goroutine example: ```go func main() { go spinner(100 * time.Millisecond) const n = 45 fibN := fib(n) // slow fmt.Printf("\rFibonacci(%d) = %d\n", n, fibN) } func spinner(delay time.Duration) { for { for _, r :=

Re: How to check if value is null, today?

2021-10-14 Thread jfondren via Digitalmars-d-learn
On Thursday, 14 October 2021 at 11:58:29 UTC, tastyminerals wrote: Here is an example code that doesn't work with the new compiler anymore: ``` if (someValue.isNull) ``` Attempting to run the above throws: ``` Error: incompatible types for `(0) : (someValue)`: `int` and `Nullable!int` ```

How to test if a string is pointing into read-only memory?

2021-10-12 Thread jfondren via Digitalmars-d-learn
std.string.toStringz always allocates a new string, but it has this note: ```d /+ Unfortunately, this isn't reliable. We could make this work if string literals are put in read-only memory and we test if s[] is pointing into that. /* Peek past end of s[], if it's 0, no conversion necessary.

Re: Linker error

2021-10-11 Thread jfondren via Digitalmars-d-learn
On Monday, 11 October 2021 at 23:43:17 UTC, Ruby The Roobster wrote: package mixin template move__() { pragma(inline) package void mv(Point moveby, ref Skeleton tomove) { foreach(i;tomove.faces) { foreach(k;i.lines) {

Re: Managing malloced memory

2021-10-11 Thread jfondren via Digitalmars-d-learn
On Monday, 11 October 2021 at 12:09:07 UTC, Imperatorn wrote: On Wednesday, 6 October 2021 at 18:06:38 UTC, anon wrote: I interface to a C library that gives me a malloced object. How can I manage that pointer so that it gets freed automatically. What I've thought of so far: * scope(exit): not

Re: Create array from range

2021-10-09 Thread jfondren via Digitalmars-d-learn
On Saturday, 9 October 2021 at 23:58:14 UTC, Greg Strong wrote: This should be a simple question, but I'm having difficult finding an answer. How do I filter some elements of an array into a new array? The filter! function returns a range, but I can't seems to assign it to a new array. I get

Re: Python's list equivalent with std.variant?

2021-10-03 Thread jfondren via Digitalmars-d-learn
On Sunday, 3 October 2021 at 22:22:48 UTC, rjkilpatrick wrote: ```d void main() { // When we use `SuperClass[] list;` here, we find 'a' is hidden by the base class Variant[] list; // Attempting to append derived class instances to list list ~= new DerivedClass(1.0f); list ~

Re: Mutually recursive template expansion

2021-10-01 Thread jfondren via Digitalmars-d-learn
On Friday, 1 October 2021 at 14:03:06 UTC, Stephen wrote: This code should work should mutual recursion be supported. It still wouldn't work, because structs are value types and it's impossible to say how large either struct is: Error: struct `mutualrec.Ar` no size because of forward referen

Re: Dynamically binding to D code using extern(D)

2021-09-30 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 18:09:46 UTC, Hipreme wrote: I write this post as both a learning tool, a question and an inquiry. There are just a lot of drawbacks in trying to do function exporting while using D. The terms that people use are a bit sloppy. There are three kinds of 'link

Re: 0 cost template instantiation

2021-09-29 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 03:13:28 UTC, jfondren wrote: As provided, loadSymbol without the "static if": 965K libhipengine_api.a with `mixin(loadSymbol("name"))` instead of a template: 749K libhipengine_api.a The difference goes down to 66K vs. 60K with `dub -brelease --compiler=gdc

Re: 0 cost template instantiation

2021-09-29 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 02:31:50 UTC, Hipreme wrote: https://github.com/MrcSnm/HipremeEngine/tree/hotload/api You may try messing at the module api.graphics.g2d.renderer2d There is a function called initG2D Try changing it from loadSymbols to each one loadSymbol. You can just dub at

Re: 0 cost template instantiation

2021-09-29 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 01:44:57 UTC, jfondren wrote: On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { st

Re: 0 cost template instantiation

2021-09-29 Thread jfondren via Digitalmars-d-learn
On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { static if(symName == "") s = cast(typeof(s))_loadSy

Re: Program crash: GC destroys an object unexpectedly

2021-09-23 Thread jfondren via Digitalmars-d-learn
On Thursday, 23 September 2021 at 14:23:40 UTC, eugene wrote: On Thursday, 23 September 2021 at 14:00:30 UTC, eugene wrote: For the moment I am personally quite happy ```d void main(string[] args) { import core.memory : GC; auto Main = new Main(); GC.addRoot(cast(void*)Main);

Re: Program crash: GC destroys an object unexpectedly

2021-09-23 Thread jfondren via Digitalmars-d-learn
On Thursday, 23 September 2021 at 13:30:42 UTC, eugene wrote: So, in C it is MY (potentially wrong) code. In D, it is NOT MY code, it is GC. Actually in both cases it is MY+the compiler's code. A very similar example from C-land (without my digging up the exact details) is something like ``

Re: foreach(ubyte j;0 .. num) is bugging out

2021-09-22 Thread jfondren via Digitalmars-d-learn
On Thursday, 23 September 2021 at 00:30:45 UTC, Ruby The Roobster wrote: I figured out something weird. The variable 'i' is passed by reference, yet the variable 'i' of the loop isn't being incremented by posfunc. I assume foreach creates a new i variable at the start of each new loop. Yep:

Re: foreach(ubyte j;0 .. num) is bugging out

2021-09-22 Thread jfondren via Digitalmars-d-learn
On Thursday, 23 September 2021 at 00:06:42 UTC, Ruby The Roobster wrote: So, I have the following function: ```d writeln(tempcolor); //For this matter, the program correctly reports tempcolor as 1... for(ubyte j = 0;j < tempcolor; j++ /*trying ++j has same effect*/ ) { //tempcolor is

Re: Program crash: GC destroys an object unexpectedly

2021-09-22 Thread jfondren via Digitalmars-d-learn
On Wednesday, 22 September 2021 at 08:03:59 UTC, eugene wrote: On Tuesday, 21 September 2021 at 20:28:33 UTC, jfondren wrote: Everything is Ok now, I don't think this is reliably OK. If you're not using Stopper later in the function, and if there are no other references to it, then the GC ca

Re: Program crash: GC destroys an object unexpectedly

2021-09-21 Thread jfondren via Digitalmars-d-learn
On Tuesday, 21 September 2021 at 20:17:15 UTC, eugene wrote: Now, change operation order in the main like this: ```d void main(string[] args) { auto Main = new Main(); auto stopper = new Stopper(); Main.run(); stopper.run(); ``` ``` d-lang/edsm-in-d-simple-example-2 $ ./test |

Re: Program crash: GC destroys an object unexpectedly

2021-09-21 Thread jfondren via Digitalmars-d-learn
On Monday, 13 September 2021 at 17:18:30 UTC, eugene wrote: I do not understand at all why GC considers those sg0 and sg1 as unreferenced. And why old gdc (without -Os) and old ldc do not. Conclusion: There's nothing special about sg0 and sg1, except that they're part of Stopper. The Stopper

Re: MobI? Really?

2021-09-21 Thread jfondren via Digitalmars-d-learn
On Tuesday, 21 September 2021 at 16:14:52 UTC, Chris_D wrote: jfondren: Sorry, but I am talking about documentation. For me, online web pages don't qualify; they are in the cloud, unreal, with no substance. Does anyone really read 300 pages online, in a web browser? Of course not. You can

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread jfondren via Digitalmars-d-learn
On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1);

Re: Program crash: GC destroys an object unexpectedly

2021-09-19 Thread jfondren via Digitalmars-d-learn
On Sunday, 19 September 2021 at 08:51:31 UTC, eugene wrote: reference-containing struct that vanishes on the return of your corresponding function I do not think it's a problem, otherwise **both programs would not work at all**. The GC doesn't reliably punish objects living past there not bei

Re: Extract base type of any array?

2021-09-18 Thread jfondren via Digitalmars-d-learn
On Sunday, 19 September 2021 at 03:58:41 UTC, Kirill wrote: How can I get the base type of any (multidimensional/static/dynamic/associative) array? Example: ``` void main() { int[][] intArr; double[4][] doubleArr; string[string][] strArr; intArr.example; // T = int doubleAr

Re: MobI? Really?

2021-09-18 Thread jfondren via Digitalmars-d-learn
On Saturday, 18 September 2021 at 20:40:56 UTC, Chris_D wrote: The "D Programming Language Specification" seems to be the most important documentation for D. Is it really only available as Mobi? That is the most bizarre choice of format I've ever seen. Chris No, it's not *only* available

Re: Program crash: GC destroys an object unexpectedly

2021-09-18 Thread jfondren via Digitalmars-d-learn
On Saturday, 18 September 2021 at 09:39:24 UTC, eugene wrote: The definition of this struct was taken from /usr/include/dmd/druntime/import/core/sys/linux/epoll.d ... If the reason for crash was in EpollEvent alignment, programs would segfaults always very soon after start, just right after the

Re: yet another segfault - array out of bound is not caught by try catch

2021-09-17 Thread jfondren via Digitalmars-d-learn
On Friday, 17 September 2021 at 11:10:33 UTC, seany wrote: Compile with `dub build --compiler=ldc2 `. this should enable array bound checking options. By default, yes. run `dub -v build --compiler=ldc2` to see the exact commands that dub runs. But should it not be caught by range error

Re: GC seems to crash my C-code function

2021-09-17 Thread jfondren via Digitalmars-d-learn
On Friday, 17 September 2021 at 06:27:40 UTC, frame wrote: Thanks, I'm just careful with casting. Does it really allocate from a literal if it's used on the stack only? Is `-vgc` switch reliable? looks to me like it calls ```d // object private U[] _dup(T, U)(scope T[] a) pure nothrow @truste

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Friday, 17 September 2021 at 05:01:36 UTC, james.p.leblanc wrote: Again, thanks to you and many of the D community with helping to learn and appreciate the capabilities of D. It is nice to be here. Yeah. The improved joinStruct is nice enough that I think it's probably a good thing to do.

Re: dub segfault and range error handling

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Thursday, 16 September 2021 at 20:49:28 UTC, seany wrote: I compile with : `dub build -b release --compiler=ldc2` The result executing the compiled binary 'myproj' is is ( whether `writeln (a[1])` is uncommented, or the `test()` function is uncommented) some random number, usually negativ

Re: Merge 2 structs together (into a single struct)?

2021-09-16 Thread jfondren via Digitalmars-d-learn
On Thursday, 16 September 2021 at 20:12:03 UTC, james.p.leblanc wrote: Is there some obvious, and simple solution to this conundrum of mine? I would consider AAs. ```d struct A { int alpha; float x = 1.23; } struct B { int beta; float y = 4.4; string s = "this is fine."; }

Re: Program crash: GC destroys an object unexpectedly

2021-09-15 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 20:59:14 UTC, Ali Çehreli wrote: On 9/14/21 9:56 AM, eugene wrote: > On Tuesday, 14 September 2021 at 16:43:50 UTC, jfondren wrote: >> The misaligned pointer and the >> reference-containing struct that vanishes on the return of your >> corresponding function are

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 16:56:52 UTC, eugene wrote: On Tuesday, 14 September 2021 at 16:43:50 UTC, jfondren wrote: GC needs to be able to stop your program nice fantasies... and find all of the live objects in it. The misaligned pointer and the reference-containing struct that vanis

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 16:15:20 UTC, eugene wrote: On Tuesday, 14 September 2021 at 16:07:00 UTC, jfondren wrote: No. And when was the first one? here: On Monday, 13 September 2021 at 18:45:22 UTC, jfondren wrote: auto p = cast(EpollEvent*) pureMalloc(EpollEvent.sizeof); What? A

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 15:37:27 UTC, eugene wrote: On Tuesday, 14 September 2021 at 14:56:00 UTC, jfondren wrote: You could fix this by having a 128-bit struct and passing C an index into it It is another "not so funny joke", isn't it? No. And when was the first one? ```d align (

Re: Program crash: GC destroys an object unexpectedly

2021-09-14 Thread jfondren via Digitalmars-d-learn
On Tuesday, 14 September 2021 at 14:40:55 UTC, eugene wrote: On Tuesday, 14 September 2021 at 12:09:03 UTC, Steven Schveighoffer wrote: This project is too big and complex Really, "too big and complex"? It's as simple as a tabouret :) It's just a toy/hobby 'project'. A 5-pound phone isn't "t

Re: Program crash: GC destroys an object unexpectedly

2021-09-13 Thread jfondren via Digitalmars-d-learn
On Monday, 13 September 2021 at 17:18:30 UTC, eugene wrote: Then after pressing ^C (SIGINT) the program gets SIGSEGV, since references to sg0 and sg1 are no longer valid (they are "sitting" in epoll_event structure). engine/ecap.d(54): Error: field `EpollEvent.es` cannot assign to misaligned

Re: Which operators cannot be overloaded and why not?

2021-09-13 Thread jfondren via Digitalmars-d-learn
On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: - condition al expression ` cond ? exp : exp ` And many other boolean operators, unary !, binary && and || https://dlang.org/spec/operatoroverloading.html lists all the overloadable operators, and https://dlang.org/spec/expression

Re: Proper way to accept either static or dynamic array as a parameter

2021-09-11 Thread jfondren via Digitalmars-d-learn
On Sunday, 12 September 2021 at 02:44:36 UTC, Alex Bryan wrote: `T[] dynArr` can be passed (by reference) to a function that takes `ref T[] data` but `T[10] data` cannot? Why not? ```d void add1(ref int[] nums) { nums ~= 1; } unittest { int[] nums; nums.add1; nums.add1; num

Re: File difference module similar to the Linux command "comm"

2021-09-11 Thread jfondren via Digitalmars-d-learn
On Saturday, 11 September 2021 at 23:17:31 UTC, Vino wrote: Hi All, May i know whether there is any module similar to the Linux command "comm" (finding difference between 2 files), if present can you please guide me through link to the page nor do let me know if there is any other solutio

Re: Array permutations

2021-09-11 Thread jfondren via Digitalmars-d-learn
On Saturday, 11 September 2021 at 19:57:26 UTC, jfondren wrote: auto pairs = list.cartesianProduct(list.drop(1)) This `drop` isn't necessary.

Re: Array permutations

2021-09-11 Thread jfondren via Digitalmars-d-learn
On Saturday, 11 September 2021 at 19:37:42 UTC, Vino wrote: Hi All, Request your help on the below to print the below array as "Required output", Was able to get these values "[1,2],[2,3],[3,4],[4,5]" by using list.slide(2), need your help to get values "1,3],[1,4],[1,5],[2,4],[2,5],[3,5]"

Re: How to simply parse and print the XML with dxml?

2021-09-09 Thread jfondren via Digitalmars-d-learn
On Thursday, 9 September 2021 at 23:29:56 UTC, Imperatorn wrote: On Thursday, 9 September 2021 at 18:40:53 UTC, jfondren wrote: On Thursday, 9 September 2021 at 17:17:23 UTC, tastyminerals wrote: [...] dxml.parser is a streaming XML parser. The documentation at http://jmdavisprog.com/docs/dx

Re: How to simply parse and print the XML with dxml?

2021-09-09 Thread jfondren via Digitalmars-d-learn
On Thursday, 9 September 2021 at 17:17:23 UTC, tastyminerals wrote: Maybe I missed something obvious in the docs but how can I just parse the XML and print its content? ``` import dxml.parser; auto xml = parseXML!simpleXML(layout); xml.map!(e => e.text).join.writeln; ``` throws `core.excepti

Re: Is std.variant useful for types only known at run time?

2021-09-08 Thread jfondren via Digitalmars-d-learn
On Wednesday, 8 September 2021 at 09:55:20 UTC, Chris Piker wrote: Interesting. I presume that the big win for using std.sumtype over a class set is value semantics instead of reference semantics? There's a lot to say about the precise differences. One practical difference that I alluded to

Re: Is std.variant useful for types only known at run time?

2021-09-08 Thread jfondren via Digitalmars-d-learn
On Wednesday, 8 September 2021 at 07:10:21 UTC, Chris Piker wrote: Hi D I'm working on data streaming reading module where the encoding of each input array isn't known until runtime. For example date-time column values may be encoded as: * An ISO-8601 UTC time string (aka char[]) * A

Re: Looking to get typeof parseXML return value

2021-09-06 Thread jfondren via Digitalmars-d-learn
On Tuesday, 7 September 2021 at 04:13:08 UTC, Chris Piker wrote: Any ideas on how to get the return type of `parseXML` below: ``` import dxml.parser; const(char)[] _mmfile; //_mmfile initialization TYPE??? _entityRng = parseXML!(simpleXML)(_mmfile); ``` *before* calling parseXML, so that it can

Re: "+=" (overloads) with custom array slices on both lhs, and rhs ??

2021-09-05 Thread jfondren via Digitalmars-d-learn
On Sunday, 5 September 2021 at 20:49:08 UTC, james.p.leblanc wrote: On Sunday, 5 September 2021 at 20:38:29 UTC, Paul Backus wrote: Please post the source code for `myarray_mod` so that we can reproduce the errors you're seeing. Hello Paul, Thanks for having a look ... James Here's a reduc

Re: Forum posting question ... how post a thread question with color syntax highlighting ??

2021-09-05 Thread jfondren via Digitalmars-d-learn
On Sunday, 5 September 2021 at 17:48:51 UTC, james.p.leblanc wrote: Dear All, I have noticed that quite a few posts and responses on this forum include d snippets made with **nicely colored syntax highlighting.** (I do not mean just the bold markdown text.) This increases post clarity signifi

Re: Why can't the DMD compiler accept files or directories with white spaces even delimited by quotes?

2021-09-04 Thread jfondren via Digitalmars-d-learn
On Saturday, 4 September 2021 at 23:50:33 UTC, Marcone wrote: Example: dmd "hello world.d" ``` $ cat hello\ world.d module helloworld; void main() { import std.stdio : writeln; writeln("without the explicit 'module', this file would"); writeln("be inferred to have an invalid module

Re: why is it a class property cannot be used like a.b ~= c; ?

2021-09-04 Thread jfondren via Digitalmars-d-learn
On Saturday, 4 September 2021 at 23:33:39 UTC, someone wrote: ```d public class cSomething { private: dstring pstrWhatever = null; public: @safe dstring whatever() { return pstrWhatever; } @safe void whatever(const dstring lstrWhatever) { pstrWhatever = lstrWhatever; } } vo

Re: Phobos Unittest

2021-09-04 Thread jfondren via Digitalmars-d-learn
On Saturday, 4 September 2021 at 20:06:27 UTC, Per Nordlöw wrote: On Saturday, 4 September 2021 at 20:05:17 UTC, Per Nordlöw wrote: ```sh time dmd import_std.d -o- ``` should be ```sh time dmd -unittest import_std.d -o- ``` When you generate the object files, I get 13K vs. 75K from a file

Re: Run-time setting of immutable variable?

2021-09-02 Thread jfondren via Digitalmars-d-learn
On Thursday, 2 September 2021 at 17:17:15 UTC, DLearner wrote: Surely there is no inconsistency - at run time the array is in a fixed place, so ArrPtr is (or at least should be) a constant, but the contents of the array can vary as the program runs. In the case of `immutable(T)* ArrPtr`, the

Re: Documentation generator is not working

2021-09-02 Thread jfondren via Digitalmars-d-learn
On Thursday, 2 September 2021 at 16:20:32 UTC, Vinod K Chandran wrote: Hi all, I am playing with ddoc. I wrote this code-- ```d import std.stdio : log = writeln; void main() { log("Experimenting with dDoc"); } /// A sample function. /// Let's check what we will get in documentation. /// abc

Re: Dustmite and linking error

2021-09-02 Thread jfondren via Digitalmars-d-learn
On Thursday, 2 September 2021 at 11:04:12 UTC, JG wrote: Hi, We hit a linking error (after upgrading to dub 1.26.0). I thought I would try to use dustmite to create a reduced error test case. One week later it is still running (depth 22). I don't suppose there is anyway of determining when it

Re: Question on Immutability

2021-08-30 Thread jfondren via Digitalmars-d-learn
On Tuesday, 31 August 2021 at 05:42:22 UTC, ag0aep6g wrote: On 31.08.21 02:50, Mike Parker wrote: Member functions marked as immutable can be called on both mutable and immutable instances. That's not true. Demonstrated: ```d struct S { int x; int get() immutable { return x; } } un

Re: byte + byte = int: why?

2021-08-29 Thread jfondren via Digitalmars-d-learn
On Sunday, 29 August 2021 at 15:57:18 UTC, Paul Backus wrote: On Sunday, 29 August 2021 at 15:42:18 UTC, Ali Çehreli wrote: Depending on the situation, you may want to use std.conv.to, which does a value range check and throws an exception to prevent an error: byte foo(byte a, byte b) {

Re: A way to mixin during runtime?

2021-08-27 Thread jfondren via Digitalmars-d-learn
On Friday, 27 August 2021 at 10:34:27 UTC, Kirill wrote: Each csv file will be different. For example: ``` name;surname;age;grade Alex;Wong;18;87 John;Doe;19;65 Alice;Doe;18;73 etc... ``` I'd like to extract the data types automatically. For instance, if using tuples: ``` Tuple!(string, strin

Re: Mixin/static if issue

2021-08-25 Thread jfondren via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 22:52:23 UTC, DLearner wrote: On Wednesday, 25 August 2021 at 22:33:00 UTC, H. S. Teoh wrote: [...} I think what you meant to write is: static if (typeof(mixin(VarName)).stringof == "uint") { You want the type of the variable named by VarName, not the t

Re: alias this - am I using it wrong?

2021-08-25 Thread jfondren via Digitalmars-d-learn
On Wednesday, 25 August 2021 at 12:11:01 UTC, Johann Lermer wrote: ```d 14 void main () 15 { 16 auto ac = new Alias_Class; 17 Test_Struct ts = ac; // compiles 18 ac = ts; // compiles as well - why? 19 20 auto tc = new Test_Class; 21 ts = tc.ac; // compi

Re: foreach() behavior on ranges

2021-08-24 Thread jfondren via Digitalmars-d-learn
On Tuesday, 24 August 2021 at 08:36:18 UTC, frame wrote: Consider a simple input range that can be iterated with empty(), front() and popFront(). That is comfortable to use with foreach() but what if the foreach loop will be cancelled? If a range isn't depleted yet and continued it will supply

  1   2   3   >