Adding a partial specialization of std.conv.to for Typedef!string

2024-09-01 Thread kdevel via Digitalmars-d-learn
In order to make this work ```d import std.typecons; alias vstring = Typedef!string; void main () { import std.stdio; import std.conv; auto v = 3.to!vstring; // ain't work out of the box writeln (v); auto w = 3.to!string; writeln (w); long l = 3.to!long; writeln (l);

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-09-01 Thread kdevel via Digitalmars-d-learn
On Saturday, 31 August 2024 at 13:48:52 UTC, ryuukk_ wrote: On Saturday, 31 August 2024 at 13:00:42 UTC, Steven Schveighoffer wrote: On Saturday, 31 August 2024 at 12:47:25 UTC, ryuukk_ wrote: ```D void main() { int[string] test; test["hello"] = 42; if (auto it = "hello" in test)

Re: Associative Array, get value instead of poiter using `if (auto ..)`, possible?

2024-08-31 Thread kdevel via Digitalmars-d-learn
On Saturday, 31 August 2024 at 14:25:29 UTC, Paul Backus wrote: [...] Once the next release of Phobos comes out, with [PR 9039][1] merged, you'll be able to do it like this: ```d import std.typecons; Nullable!V maybeGet(K, V)(V[K] aa, K key) { if (auto ptr = key in aa) return null

Re: Socket and spawn()

2024-05-31 Thread kdevel via Digitalmars-d-learn
On Friday, 31 May 2024 at 16:07:23 UTC, Andy Valencia wrote: I'm coding a server which takes TCP connections. I end up in the main thread with .accept() which hands me a Socket. I'd like to hand this off to a spawn()'ed thread to do the actual work. Have you taken into consideration that ea

Re: mmap file performance

2024-04-17 Thread kdevel via Digitalmars-d-learn
On Thursday, 11 April 2024 at 16:23:44 UTC, Andy Valencia wrote: [...] void main(in string[] argv) ^^ What if you want to use bool memorymapped; getopt (argv, "m", &memorymapped); inside main? [1] Have you tried using "rm" [2] instead of "r" as stdioOpenmode under Linux for a

Re: Why is this code slow?

2024-03-24 Thread kdevel via Digitalmars-d-learn
On Sunday, 24 March 2024 at 19:31:19 UTC, Csaba wrote: I know that benchmarks are always controversial and depend on a lot of factors. So far, I read that D performs very well in benchmarks, as well, if not better, as C. I wrote a little program that approximates PI using the Leibniz formula.

How use SafeRefCounted in @safe code safely?

2024-03-23 Thread kdevel via Digitalmars-d-learn
```d @safe: void foo () { import std.typecons : SafeRefCounted; SafeRefCounted!int s; } unittest { import std.exception : assertNotThrown; assertNotThrown (foo); } ``` ``` $ dmd -unittest -main -run sr.d sr.d(6): Error: `@safe` function `sr.foo` cannot call `@system` destructor `s

Re: chain of exceptions, next method

2024-03-06 Thread kdevel via Digitalmars-d-learn
On Saturday, 10 September 2022 at 08:48:39 UTC, Andrej Mitrovic wrote: [...] I wish the compiler would rewrite scope(failure) to use chained exceptions. Otherwise any exceptions thrown within scope(failure) can end up losing information about what was the original exception that was thrown.

DIP 1036e not on the DIPs list?

2024-02-23 Thread kdevel via Digitalmars-d-learn
The DIP 1036e is not listed in https://github.com/dlang/DIPs/tree/master/DIPs is this intentional?

Searching for i" in the forum

2024-02-23 Thread kdevel via Digitalmars-d-learn
How do I search for i" in the forum? I get the following errors: i" -> Error: malformed MATCH expression: [i"] (1) i\" -> Error: malformed MATCH expression: [i\"] (1) 'i"' -> Error: malformed MATCH expression: ['i"'] (1) `i"` -> Error: malformed MATCH expression: [`i"`] (1) "i

Re: length's type.

2024-02-08 Thread kdevel via Digitalmars-d-learn
On Thursday, 8 February 2024 at 16:54:36 UTC, Kevin Bailey wrote: [...] On Thursday, 8 February 2024 at 15:26:16 UTC, kdevel wrote: Elegant and correct is this version: ```d import std.stdio; int main() { char[] something = ['a', 'b', 'c']; writeln("len: ", something.length);

Re: length's type.

2024-02-08 Thread kdevel via Digitalmars-d-learn
On Thursday, 8 February 2024 at 15:00:54 UTC, Kevin Bailey wrote: By all means, please share with us how you would have written that just as elegantly but "correct". Elegant and correct is this version: ```d import std.stdio; int main() { char[] something = ['a', 'b', 'c']; w

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

2024-02-03 Thread kdevel via Digitalmars-d-learn
On Saturday, 3 February 2024 at 02:20:13 UTC, Paul Backus wrote: On Friday, 2 February 2024 at 23:25:37 UTC, Chris Katko wrote: The auto solution won't work for a struct however which I'm using: ```D struct procTable{ //contains all the fields inside a file I'm parsing uint time; int p

Re: FileException when calling getTimes on a DirEntry

2023-12-26 Thread kdevel via Digitalmars-d-learn
On Tuesday, 26 December 2023 at 21:09:05 UTC, Renato wrote: On Sunday, 24 December 2023 at 21:18:44 UTC, kdevel wrote: [...] I would have expected you asking questions like "Which program might have generated that symlink?", "How do I get the meta-data from the symlink and not from the file it

Re: FileException when calling getTimes on a DirEntry

2023-12-24 Thread kdevel via Digitalmars-d-learn
On Sunday, 24 December 2023 at 20:00:15 UTC, Renato wrote: I asked what could be causing an Exception in my code to happen as that was quite unexpected. As I already wrote: Your code tries to fetch the meta-data for an object that does not exist. [..] Have you ever seen a symlink like the o

Re: FileException when calling getTimes on a DirEntry

2023-12-24 Thread kdevel via Digitalmars-d-learn
On Sunday, 24 December 2023 at 14:19:18 UTC, Renato wrote: I was trying to use a library (fswatch) for watching the file system Watching for what? [...] My code is really basic, when the directory modified timestamp changes, I list the directory entries with `dirEntries` and then call `dirE

Re: now I need -allinst when dmd compiles the unittest

2023-12-16 Thread kdevel via Digitalmars-d-learn
On Tuesday, 5 December 2023 at 03:36:04 UTC, Steven Schveighoffer wrote: Are you using -checkaction=context? Right. [...] For reference: https://issues.dlang.org/show_bug.cgi?id=22374 https://issues.dlang.org/show_bug.cgi?id=22902 https://issues.dlang.org/show_bug.cgi?id=19937 You even repo

Re: Changing behavior of associative array

2023-12-16 Thread kdevel via Digitalmars-d-learn
On Saturday, 16 December 2023 at 20:04:54 UTC, Kevin Bailey wrote: I've added a TON of writeln's to confirm this. The *instant* I made the parameter "ref", the real program starts acting as expected, and the print-outs show the correct results. If you comment out this line ``` //m[f] = 1;

now I need -allinst when dmd compiles the unittest

2023-12-01 Thread kdevel via Digitalmars-d-learn
If I not use -allinst the linker complains when using the current msgpack-d v1.0.5, e.g. [...]msgpack-d/src/msgpack/package.d:203: undefined reference to `pure nothrow @nogc @safe immutable(char)[] core.internal.dassert._d_assert_fail!(int)._d_assert_fail!(int)._d_assert_fail(scope const(immut

"using `in ref` is deprecated" in client code while the module's unittest does not warn

2023-12-01 Thread kdevel via Digitalmars-d-learn
After switching to dmd v2.105.3 I get this warnings almost everywhere. Do I really have to fork msgpack-d in order to get rid of these warnings? Now I replaced every "in ref" with "in" in my own code but I do not add that preview flag to the compiler invocation. Is that safe?

Re: struct initializer

2023-12-01 Thread kdevel via Digitalmars-d-learn
On Wednesday, 29 November 2023 at 16:48:09 UTC, Paul Backus wrote: [...] If you're using a new enough compiler, it even supports named arguments: S3 fun2() { return S3(b: 2, a: 5); } Indeed. Seems to be in dmd since 2.103.0 (2.102.2 didn't support this syntax). Alas, the Change Log [1] re

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-30 Thread kdevel via Digitalmars-d-learn
On Tuesday, 28 November 2023 at 09:43:47 UTC, Dom DiSc wrote: On Tuesday, 28 November 2023 at 08:51:21 UTC, Mark Davies wrote: On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote: ``` import std.stdio; char[10] longToString(long n) @nogc ``` For a 'long' 10 characters is likely to be not

Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-30 Thread kdevel via Digitalmars-d-learn
On Friday, 24 November 2023 at 13:05:30 UTC, Ferhat Kurtulmuş wrote: [...] ``` import core.stdc.stdio : sprintf; import core.stdc.math : log10; import std.exception : assumeUnique; import std.stdio : writeln; size_t nod(int num){ return cast(size_t)((num==0)?1:log10(num)+1); }

Re: D: How do I pipe (|) through three programs using std.process?

2023-11-19 Thread kdevel via Digitalmars-d-learn
On Saturday, 18 November 2023 at 18:09:53 UTC, BoQsc wrote: Latest iteration on this thread. Limitations: * pipes through two programs. * very verbose, hard to use. What exactly are you trying to achieve? ``` import std; import std.process; version (Windows) { enum Find = "find"; } version

Re: D: How do I pipe (|) through three programs using std.process?

2023-11-11 Thread kdevel via Digitalmars-d-learn
On Saturday, 11 November 2023 at 17:29:14 UTC, BoQsc wrote: https://dlang.org/library/std/process.html How do I pipe (|) through three programs using std.process? ``` echo This is a sample text | find "sample" | find "text" ``` ```d import std.stdio; import std.process; version (Windows) { e

Re: Finding duplicate elements

2023-08-15 Thread kdevel via Digitalmars-d-learn
On Tuesday, 15 August 2023 at 17:59:27 UTC, vino wrote: Request your help in finding duplicate element without sorting as per the below example ```d module remove_duplicates; import std.stdio; import std.format : format; import std.string : strip; int main (string [] args) { bool [string]

Re: "macro" expansion to build switch case code

2023-07-02 Thread kdevel via Digitalmars-d-learn
On Sunday, 2 July 2023 at 17:02:44 UTC, Paul wrote: I have a struct similar to the following example. I'd like to build an adder method without having to code the whole method. How do I use the D language to do this? Template, mixins, CTFE..all of them? ```d struct myS { int a, b, c, d

Re: string to char[4] FourCC conversion

2023-05-27 Thread kdevel via Digitalmars-d-learn
On Friday, 26 May 2023 at 13:18:15 UTC, Steven Schveighoffer wrote: [...] This worked for me: ```d char[4] fourC(string s) { if(s.length >= 4) return s[0 .. 4]; Silent truncation? Non-ASCII chars? char[4] res = 0; According to [1], [2] or [3] that should read ``` char[

Re: Lockstep iteration in parallel: Error: cannot have parameter of type `void`

2023-05-23 Thread kdevel via Digitalmars-d-learn
On Saturday, 20 May 2023 at 18:27:47 UTC, Ali Çehreli wrote: [...] And I've just discovered something. Me2! The serial version using array indexing void vec_op_naive0 (double [] outp, const double [] inp, double function (double) fp) { enforce (inp.length == outp.length);

Re: Lockstep iteration in parallel: Error: cannot have parameter of type `void`

2023-05-20 Thread kdevel via Digitalmars-d-learn
Thanks for your explications! On Friday, 19 May 2023 at 21:18:28 UTC, Ali Çehreli wrote: [...] - std.range.zip can be used instead but it does not provide 'ref' access to its elements. How/why does sort [1] work with zipped arrays? [...] The following amap example there may be useful for y

Re: request assistance resolving a std.net.curl segmentation fault

2023-05-20 Thread kdevel via Digitalmars-d-learn
On Friday, 19 May 2023 at 23:36:28 UTC, anonymouse wrote: [...] The reason I used a while loop was to detect loss of internet connection and resume the process once the connection is re-established. What if the internet connection is not re-established within an reasonable amount of time? Wh

Re: request assistance resolving a std.net.curl segmentation fault

2023-05-19 Thread kdevel via Digitalmars-d-learn
On Friday, 19 May 2023 at 11:07:01 UTC, anonymouse wrote: What am I doing wrong here? [...] curl.set(CurlOption.writedata, &fp); According to [1] this line must read ``` curl.set(CurlOption.writedata, cast (void *) fp.getFP()); ``` [1] https://curl.se/libcurl/c/CURLOPT_WRITEDAT

Lockstep iteration in parallel: Error: cannot have parameter of type `void`

2023-05-19 Thread kdevel via Digitalmars-d-learn
``` import std.range; import std.parallelism; void vec_op (double [] outp, const double [] inp, double function (double) f) { foreach (ref a, b; parallel (lockstep (outp, inp))) a = f (b); } ``` Should this compile? dmd says ``` [...]/src/phobos/std/parallelism.d(4094): Error: canno

Re: Returning a reference to be manipulated

2023-04-15 Thread kdevel via Digitalmars-d-learn
On Saturday, 15 April 2023 at 15:50:18 UTC, Dennis wrote: [...] care about the type / mutability of the pointer. Returning `i`'s address in a long does not trigger the escape detector: ``` long foo (long s, return ref int i) { s = cast (long) &i; return s; } auto bar () { int i;

Re: Returning a reference to be manipulated

2023-04-15 Thread kdevel via Digitalmars-d-learn
On Saturday, 15 April 2023 at 14:10:57 UTC, Dennis wrote: [...] This adds complexity, just to add some 'intermediate' safety between `@system` and `@safe` in a few cases. It's better to keep the rules simple and consistent. Thanks for the answer! While playing around with return ref I came a

Re: Returning a reference to be manipulated

2023-04-15 Thread kdevel via Digitalmars-d-learn
On Saturday, 15 April 2023 at 13:24:52 UTC, Richard (Rikki) Andrew Cattermole wrote: On 16/04/2023 1:20 AM, kdevel wrote: On Saturday, 15 April 2023 at 12:45:31 UTC, Richard (Rikki) Andrew Cattermole wrote: It was bad analysis by the compiler, which has since been corrected. It should have be

Re: Returning a reference to be manipulated

2023-04-15 Thread kdevel via Digitalmars-d-learn
On Saturday, 15 April 2023 at 12:45:31 UTC, Richard (Rikki) Andrew Cattermole wrote: It was bad analysis by the compiler, which has since been corrected. It should have been applied only to @safe code. But why is the @unsafe programmer now left unprotected in cases like this ``` ref int fo

Re: Returning a reference to be manipulated

2023-04-15 Thread kdevel via Digitalmars-d-learn
On Friday, 14 April 2023 at 11:18:21 UTC, Dennis wrote: On Friday, 14 April 2023 at 10:31:58 UTC, kdevel wrote: But in fact it is returned unless it is `return ref`. When using `return ref`, `return scope`, `scope` etc., you should be using the latest compiler and annotate functions you want

Re: Returning a reference to be manipulated

2023-04-14 Thread kdevel via Digitalmars-d-learn
On Friday, 14 April 2023 at 09:42:14 UTC, Bastiaan Veelo wrote: [...] Up to dmd v2.100.2 I am warned/get an error during compilation: ``` $ dmd returnref2.d returnref2.d(3): Deprecation: returning `i` escapes a reference to parameter `i` returnref2.d(1):perhaps annotate the parameter wi

Re: Returning a reference to be manipulated

2023-04-13 Thread kdevel via Digitalmars-d-learn
On Thursday, 13 April 2023 at 22:09:48 UTC, Jacob Shtokolov wrote: [...] ref opIndex(string key) return [...] Regarding the return ref I found this code of 2019 on my harddisk which is from or was motivated by a dconf talk: ``` ref int foo (ref int i) { return i; } ref int bar () {

Re: 'auto' keyword

2023-03-12 Thread kdevel via Digitalmars-d-learn
On Sunday, 12 March 2023 at 13:27:05 UTC, Adam D Ruppe wrote: [...] *any* storage class will work for type inference. [...] After heaving read [1] I immediately thought of this: void main () { deprecated i = 3; i = 4; } $ dmd test.d test.d(4): Deprecation: variable `

Should importC fail on invalid C code?

2023-01-13 Thread kdevel via Digitalmars-d-learn
After reading Walter's remark "ImportC sees those macro definitions and transforms them into manifest constant declarations" in Issue 23622 - ImportC #defines conflict with declarations I wondered how it was implemented: `myccode.c` ``` int getx () { return X; #define X 1 } ``` `imc.d

Re: Why does the importC example not compile?

2023-01-13 Thread kdevel via Digitalmars-d-learn
On Friday, 13 January 2023 at 12:20:23 UTC, Dennis wrote: I don't think there's a way to test examples of separate compilation in the spec currently. What must be added or changed in order to test every example which is intended to produce an executable?

Why does the importC example not compile?

2023-01-13 Thread kdevel via Digitalmars-d-learn
https://dlang.org/spec/importc.html `square.c` ``` int square(int i) { return i * i; } ``` `demo.d` ``` import std.stdio; import square; void main() { int i = 7; writefln("The square of %s is %s", i, square(i)); } ``` ``` $ dmd --version DMD64 D Compiler v2.101.1 Copyright (C) 1999-2

Re: dirEntries removes entire branches of empty directories

2022-11-14 Thread kdevel via Digitalmars-d-learn
On Monday, 14 November 2022 at 21:05:01 UTC, kdevel wrote: [...] the runtimes are ftw : 98 ms, 470 ÎŒs, and 2 *beeep* dirEntries: 170 ms, 515 ÎŒs, and 2 *beeep* (to be continued) When I examine the process with strace it appears that the ftw version gets the whole information fro

Re: dirEntries removes entire branches of empty directories

2022-11-14 Thread kdevel via Digitalmars-d-learn
On Friday, 11 November 2022 at 16:00:12 UTC, Ali Çehreli wrote: On 11/11/22 05:13, kdevel wrote: > dmd -O compiled patched (see below!) version applied to /usr/bin on my > desktop > yields: > > ftw : 363 ms, 750 ÎŒs, and 5 [*] > dirEntries: 18 secs, 831 ms, 738 ÎŒs, and 3 [*] Great. I did

Re: dmd 2.099 regression: unittest -checkaction=context and import std.regex cause lots of undefined references

2022-11-14 Thread kdevel via Digitalmars-d-learn
On Monday, 14 November 2022 at 17:08:38 UTC, Gavin Ray wrote: Just came here to say I hit the same bug, here's my import list: * https://issues.dlang.org/show_bug.cgi?id=19937 object._d_assert_fail linker error if compiling with -checkaction=context * https://issues.dlang.org/show_bug.cgi?

Re: dirEntries removes entire branches of empty directories

2022-11-11 Thread kdevel via Digitalmars-d-learn
On Thursday, 10 November 2022 at 21:27:28 UTC, Ali Çehreli wrote: On 11/9/22 12:06, Ali Çehreli wrote: > I am using its sibling 'ftw' Now that we know that dirEntries works properly, I decided not to use ftw. However, ftw performs about twice as fast as dirEntries (despite some common code

Re: dirEntries removes entire branches of empty directories

2022-11-09 Thread kdevel via Digitalmars-d-learn
On Wednesday, 9 November 2022 at 19:05:58 UTC, Ali Çehreli wrote: In case it matters, the file system is ext4. My code runs in tmp (tmpfs). 2) Make a sub-directory: mkdir deleteme/a Running the program shows no output; 'a' is not visited as a directory entry. Was say strace/ltrace? ``

Re: Generate a pointer to a method of a struct

2022-10-14 Thread kdevel via Digitalmars-d-learn
On Saturday, 15 October 2022 at 00:31:47 UTC, Iain Buclaw wrote: ``` auto funcptr (alias method) () { return &method; } : fun = funcptr!bar; : ``` Which works but neither dmd nor gdc were able to optimize the additional function call away. pragma(inline, true) auto funcpt

Generate a pointer to a method of a struct

2022-10-14 Thread kdevel via Digitalmars-d-learn
Given a struct `S` with method `foo`: Any of these expressions ``` &foo &S.foo &.S.foo ``` when they occur inside the struct they represent a delegate and not a function pointer. Is it okay to "extract" and use the function pointer from the delegate in this way: ``` struct S { void

Re: private method callable from other module

2022-10-08 Thread kdevel via Digitalmars-d-learn
On Saturday, 8 October 2022 at 15:56:01 UTC, Jack Pope wrote: Altering the definition sequence in b.d to have the private version second has the desired result. Otherwise, when following private foo, it looks like public foo gets adopted as a public constructor. The same for classes. Created

Re: private method callable from other module

2022-10-08 Thread kdevel via Digitalmars-d-learn
On Saturday, 8 October 2022 at 10:05:33 UTC, kdevel wrote: ``` $ dmd -g -unittest -main -run a.d b.d a.o: In function `_D1a16__unittest_L2_C1FZv': (...)./a.d:5: undefined reference to `_D1b1S3fooMFhZv' collect2: error: ld returned 1 exit status Error: linker exited with status 1 ``` `b.d` is th

Re: private method callable from other module

2022-10-08 Thread kdevel via Digitalmars-d-learn
On Saturday, 8 October 2022 at 09:59:17 UTC, kdevel wrote: On Saturday, 8 October 2022 at 09:46:59 UTC, kdevel wrote: ``` $ dmd -g -unittest -main a.d b.d $ ./a void b.S.foo(ubyte c) 1 modules passed unittests ``` 2.086.1 a.d(5): Error: struct `b.S` member foo is not accessible 2.09

Re: private method callable from other module

2022-10-08 Thread kdevel via Digitalmars-d-learn
On Saturday, 8 October 2022 at 09:46:59 UTC, kdevel wrote: ``` $ dmd -g -unittest -main a.d b.d $ ./a void b.S.foo(ubyte c) 1 modules passed unittests ``` 2.086.1 a.d(5): Error: struct `b.S` member foo is not accessible 2.090.1 compiles

private method callable from other module

2022-10-08 Thread kdevel via Digitalmars-d-learn
Is this a known bug? ``` // file b.d import std.stdio; struct S { private void foo (ubyte c) { writeln (__PRETTY_FUNCTION__); } void foo () { } } ``` ```a.d // file a.d unittest { import b; auto s = S (); s.foo ('x'); } ``` ``` $ dmd -g -unittest -main a.d b.d

Re: Is `void` the correct way to say "do not initialize this variable"?

2022-10-06 Thread kdevel via Digitalmars-d-learn
On Monday, 3 October 2022 at 15:56:02 UTC, Paul Backus wrote: Shouldn't this read Unspecified Value: If a void initialized variable's value is used before it is set, its value is unspecified. Yes, it should. Many of the contributors to the D spec are not very well versed in the precis

Re: Is `void` the correct way to say "do not initialize this variable"?

2022-10-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 2 October 2022 at 23:37:26 UTC, ryuukk_ wrote: I got the answer thanks to IRC chat: https://dlang.org/spec/declaration.html#void_init Quote: Implementation Defined: If a void initialized variable's value is used before it is set, its value is implementation defined. Shouldn

chain of exceptions, next method

2022-08-13 Thread kdevel via Digitalmars-d-learn
Quote from `src/druntime/src`: ``` /** * Returns: * A reference to the _next error in the list. This is used when a new * $(D Throwable) is thrown from inside a $(D catch) block. The originally * caught $(D Exception) will be chained to the new $(D Throwable) via this

Re: How to use exceptions

2022-08-13 Thread kdevel via Digitalmars-d-learn
On Saturday, 13 August 2022 at 13:36:08 UTC, Christian Köstlin wrote: [...] 1. error handling in main path: exactly thats what I would like todo. but for that the errors that raise need to have meaningful information. this is exactly what I am trying in those context* functions ... they do not

Re: How to use exceptions

2022-08-13 Thread kdevel via Digitalmars-d-learn
On Friday, 12 August 2022 at 21:41:25 UTC, Christian Köstlin wrote: which would enable something like ```d return s .readText .parseJSON .contextWithException((UTFException e) { return new Exception("Cannot process UTF-8 in config file%s\n %s".format(

Re: Acess variable that was set by thread

2022-08-08 Thread kdevel via Digitalmars-d-learn
On Monday, 8 August 2022 at 17:45:03 UTC, bauss wrote: On Monday, 8 August 2022 at 13:55:02 UTC, ag0aep6g wrote: auto x = s.x; [...] Your problem is here and not because it was __gshared. You're copying the value and obviously it can be changed in the meantime, that's common sense.

code review: splitIds from DConf '22 day 3: saving a sort and "getting performance"

2022-08-04 Thread kdevel via Digitalmars-d-learn
At DConf '22 day 3 Robert Schadek presented at around 07:22:00 in the YT video the function `splitIds`. Given an HTML page from bugzilla containing a list of issues `splitIds` aims at extracting all bug-ids referenced within a specific url context: ``` long [] splitIds (string page) { enum

Re: Combining JSON arrays into a single JSON array -- better way than this?

2022-08-01 Thread kdevel via Digitalmars-d-learn
On Monday, 1 August 2022 at 07:35:34 UTC, Christian Köstlin wrote: [...] ``` An arguably shorter solution (that drops some of your logging) could be: ```d import std; void main() { dirEntries(".", "*.json", SpanMode.shallow) .filter!(f => !f.name.canFind("output")) .map!(r

Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 16:03:46 UTC, Alexander Zhirov wrote: [...] How did you manage to get hold of this compiler? ``` /root/usr/program/gcc/9.5.0/install/bin/cc ``` Where does this compiler come from? This is an unpacked archive from an official source from the GNU website https:/

Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 15:25:00 UTC, Alexander Zhirov wrote: [...] Everything falls on the same error. ```sh checking for suffix of object files... configure: error: in `/home/thinstation/source/gcc/12.1.0/build/i586-pc-linux-gnu/libgcc': configure: error: cannot compute suffix of object

Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 15:25:00 UTC, Alexander Zhirov wrote: On Thursday, 28 July 2022 at 13:16:26 UTC, kdevel wrote: On Thursday, 28 July 2022 at 12:45:51 UTC, Alexander Zhirov wrote: [...] I have already downloaded the latest GCC sources, nothing compiles anyway. How did you manage t

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 14:57:36 UTC, pascal111 wrote: [...] Sure. What effect do YOU hope to causes or prevent by writing ``` /**/ ``` between all of your functions? I'm normal programmer, by mean that I'm not so expert in C matters to know reall

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 13:58:24 UTC, pascal111 wrote: [...] Precisely in what way? I am not kidding. I am seriously asking the question: In what way may a C or C++ compiler benefit from lines between functions which contain only comments consisting of nothing else than asterisks? Seriou

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 12:44:19 UTC, pascal111 wrote: [...] Do you think it helps the compiler if you put these `/**/` between your functions? Or is there anybody else who benefits from it? "Do you think it helps the compiler if you put these" Ar

Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 12:45:51 UTC, Alexander Zhirov wrote: [...] I have already downloaded the latest GCC sources, nothing compiles anyway. How did you manage to get hold of this compiler? ``` /root/usr/program/gcc/9.5.0/install/bin/cc ``` Everything falls on the same error. ```sh c

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 12:25:05 UTC, pascal111 wrote: [...] ofix.c: In function 'fix': ofix.c:7:3: warning: 'z' is used uninitialized [-Wuninitialized] 7 | y=modf(x,z); | ^ ofix.c:5:12: note: 'z' was declared here 5 | double y,* z; |^ ``` I woul

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 12:26:50 UTC, pascal111 wrote: [...] Aha! you mean "/**/", it has no job, just to separate between functions codes. Do you think it helps the compiler if you put these `/**/` between

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Wednesday, 27 July 2022 at 18:19:34 UTC, pascal111 wrote: I made a library of some useful functions while I was studying C, and I'm curious to know if D has equivalents or some ones for some of my functions, or I have to retype 'em again in D. The library link: https://github.com/pascal111-

Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 10:39:06 UTC, Alexander Zhirov wrote: [...] I don't understand what I need to do. You wrote At first I thought that I needed to rebuild the GCC compiler for the i586 architecture. I downloaded GCC 9.5.0 and started the installation: Then you wrote that

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 00:46:19 UTC, pascal111 wrote: On Thursday, 28 July 2022 at 00:36:54 UTC, ryuukk_ wrote: I don't remember the exact syntax for GDC, but it should be pretty similar to DMD You need to pass the module to the compiler gdc main.d dcollect.d I'm using CODE::BLOCK

Re: Build for i586

2022-07-28 Thread kdevel via Digitalmars-d-learn
On Thursday, 28 July 2022 at 06:12:49 UTC, Alexander Zhirov wrote: On Thursday, 28 July 2022 at 06:01:17 UTC, Alexander Zhirov wrote: ```sh /root/usr/program/gcc/9.5.0/install/bin/cc app.o -o app -L/root/usr/program/ldc/1.30/install/lib -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -lrt -ldl

Re: Particular exceptions names

2022-07-27 Thread kdevel via Digitalmars-d-learn
On Wednesday, 27 July 2022 at 09:35:12 UTC, Ali Çehreli wrote: The following program show an example as well as 'enforce', which I prefer over explicit if+throw+else: Me too. enforce!MissingArguments(args.length == 42, format!"Too few arguments: %s"(args.length)

Re: Particular exceptions names

2022-07-27 Thread kdevel via Digitalmars-d-learn
On Tuesday, 26 July 2022 at 23:43:59 UTC, pascal111 wrote: In next example code, it used user-made exception, [...] try { if( b == 0 ) { throw new Exception("Cannot divide by zero!"); } else { result = format("%s",a/b); } [..

Re: Choosing the correct compiler version

2022-07-20 Thread kdevel via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 23:19:28 UTC, jfondren wrote: Thanks for your thorough presentation. [...] Another option is to get newer glibc onto this system (not installing it, just making it available for dmd. use LD_LIBRARY_PATH). On older systems the dynamic loader (ld.so) may not execut

Re: Comparing Exceptions and Errors

2022-06-16 Thread kdevel via Digitalmars-d-learn
On Thursday, 16 June 2022 at 13:54:52 UTC, Steven Schveighoffer wrote: [scope (success) lowered to finally] [...] Furthermore I always thought of scope guards as a means for cleanup. Cleanup implies in my eyes removing things which have been used in a previous task. This intended use is docu

Re: Comparing Exceptions and Errors

2022-06-16 Thread kdevel via Digitalmars-d-learn
On Thursday, 16 June 2022 at 11:28:32 UTC, bauss wrote: [...] https://dlang.org/spec/statement.html#scope-guard-statement Quote (again): "A [...] scope(success) statement may not exit with a throw [...]." [...] If the spec forbids it, but the compiler allows it, wouldn't it then be a bug? W

Re: Comparing Exceptions and Errors

2022-06-16 Thread kdevel via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 20:46:56 UTC, Steven Schveighoffer wrote: [...] It has not harmed my code though. I tried throwing inside a scope guard, and it just works, I'm not sure why you can't throw in those? You can but that is not acceptable for the spec explicitly forbids that:

Re: Comparing Exceptions and Errors

2022-06-15 Thread kdevel via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 03:09:56 UTC, Steven Schveighoffer wrote: I don't see what you see wrong with the code I wrote. It's straightforward, obvious, and does the job I need it to do, in a way that's not prone to future mistakes. Sometimes it is not easy to explain why code "feels" wron

Re: Comparing Exceptions and Errors

2022-06-14 Thread kdevel via Digitalmars-d-learn
On Monday, 13 June 2022 at 13:15:42 UTC, Steven Schveighoffer wrote: Possibly, but I don't close the handle. It goes back to a pool to get reused. Um. I need a (fresh) connection per CGI process. I wonder if nowadays the TLS startup between the browser and the webserver isn't at least one o

Re: Comparing Exceptions and Errors

2022-06-12 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 23:57:19 UTC, Steven Schveighoffer wrote: On 6/5/22 6:09 PM, kdevel wrote: On Sunday, 5 June 2022 at 20:53:32 UTC, Steven Schveighoffer wrote: [...] For this purpose nobody needs a separate subclass named `Error`. That works with `Exception`s. You can use Exceptions

Re: Comparing Exceptions and Errors

2022-06-12 Thread kdevel via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 18:37:13 UTC, Steven Schveighoffer wrote: [...] My very common use of `scope(failure)` for my DB code: ```d conn.exec("START TRANSACTION"); scope(success) conn.exec("COMMIT"); scope(failure) conn.exec("ROLLBACK"); ``` Are there multiple (successful) returns in your

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 21:08:11 UTC, Steven Schveighoffer wrote: [...] Just FYI, this is a *different discussion* from whether Errors should be recoverable. The wording of this "question" bothers me really. What does "Errors" mean here? If you mean thrown object having a (sub)type of `Err

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 20:53:32 UTC, Steven Schveighoffer wrote: [...] For this purpose nobody needs a separate subclass named `Error`. That works with `Exception`s. You can use Exceptions instead. But the difference is they are part of the program instead of considered a check on the pro

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 17:04:49 UTC, Ali Çehreli wrote: On 6/5/22 08:07, kdevel wrote: [...] Like many other programmers who include me, Sean Parent may be right.[1] Other than being a trivial example to make a point, the code I've shown may be taking advantage of the "structure of array"

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 14:24:39 UTC, Ali Çehreli wrote: [...] struct S { int[] a; int[] b; void add(int i) {// <-- Both arrays always same size a ~= i; b ~= i * 10; } void foo() { assert(a.length == b.length); // <-- Invariant check // ... } } void main() {

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 07:21:18 UTC, Ola Fosheim Grøstad wrote: [...] The reality is that software is layered. Faults at different layers should have different consequences at the discretion of a capable programmer. +1

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 01:43:06 UTC, Steven Schveighoffer wrote: [...] But you aren't perfect, and so maybe you make a mistake, and trigger an Error. The compiler handles this unexpected condition by unwinding the stack back to the main function, printing the error and exiting, so you can

Re: Comparing Exceptions and Errors

2022-06-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 5 June 2022 at 00:40:26 UTC, Ali Çehreli wrote: [...] Errors are thrown when the program is discovered to be in an invalid state. The following program throws an `Error` in popFront: import std.range; void main () { int [1] a; auto q = a[1..$]; // line 6

Re: Comparing Exceptions and Errors

2022-06-04 Thread kdevel via Digitalmars-d-learn
On Saturday, 4 June 2022 at 16:55:31 UTC, Steven Schveighoffer wrote: [...] The point of an `Error` is that your code can assume it cannot happen. If it does happen, the code is invalid. According to my favorite dictionary "assume" means "take for granted" [1]. If `Error`s may happen how can

Re: Comparing Exceptions and Errors

2022-06-04 Thread kdevel via Digitalmars-d-learn
On Saturday, 4 June 2022 at 14:05:14 UTC, Paul Backus wrote: [...] What does that mean? Am I `Error` blind? Generally you do not need to subclass `Error` yourself. The most common way of throwing an `Error` in user code is to use `assert`, which (with default compiler flags) throws an `As

Re: Comparing Exceptions and Errors

2022-06-04 Thread kdevel via Digitalmars-d-learn
On Friday, 3 June 2022 at 23:40:50 UTC, Steven Schveighoffer wrote: During the last beerconf, I wrote a short blog post about how `Error` and `Exception` are different, and why you should never continue after catching `Error`s. Feedback welcome, I didn't announce here when I wrote it because

Re: dmd 2.099 regression: unittest -checkaction=context and import std.regex cause lots of undefined references

2022-05-28 Thread kdevel via Digitalmars-d-learn
On Friday, 18 March 2022 at 19:42:02 UTC, Anonymouse wrote: On Thursday, 17 March 2022 at 14:00:45 UTC, kdevel wrote: If ```import std.regex;``` is commented out or if ```-checkaction=context``` is removed from the cmd line the unittest passes. Can anybody reproduce this? https://run.dlang.io

Re: gdc 12.1: undefined references when linking separately compiled files

2022-05-28 Thread kdevel via Digitalmars-d-learn
On Saturday, 28 May 2022 at 15:10:25 UTC, Steven Schveighoffer wrote: [...] Is this specific to gdc, or does it happen for other compilers as well? The former.

Re: gdc 12.1: undefined references when linking separately compiled files

2022-05-28 Thread kdevel via Digitalmars-d-learn
On Saturday, 28 May 2022 at 14:37:07 UTC, kdevel wrote: dmd: ``` $ dmd -c ppinsta.d $ dmd -c parser.d $ dmd -of=ppinsta ppinsta.o parser.o $ ./ppinsta [] ``` (checking ldc/ldmd2 later) ``` $ ldc2 -c ppinsta.d && ldc2 -c parser.d && ldc2 -of=ppinsta ppinsta.o parser.o && ./ppinsta [] $ ldmd2

  1   2   3   4   >