Re: Using std.algorithm.iteration to Calculate Hamming Distance
On Sunday, 23 June 2019 at 13:10:51 UTC, Samir wrote: D already has a function to calculate the Levenshtein distance[1]. I am trying to come up with a function to calculate the Hamming distance[2] between two strings, `a` and `b`. So far, this seems to work: foreach (i, j; zip(a, b)) { if (i != j) ++hammingDistance; } zip( "hello world", "Hello World" ).map!"a[0] != a[1]".sum
Re: What is iota function full name
On Friday, 21 June 2019 at 19:18:02 UTC, KnightMare wrote: On Friday, 21 June 2019 at 12:02:10 UTC, Jonathan M Davis wrote: auto goodName( ... ) { pragma( inline, true ) return terribleName( ... ); } hmm.. I have a question: this pragma will inline terribleName (double code) or goodName (fine)?
Re: What is iota function full name
On Friday, 21 June 2019 at 12:02:10 UTC, Jonathan M Davis wrote: On Friday, June 21, 2019 5:10:03 AM MDT JN via Some folks argued a while back that iota was a terrible name and that it should be changed, but it was decided not to change it. auto terribleName( ... ) { } auto goodName( ... ) { pragma( inline, true ) return terribleName( ... ); } everyone is happy
Re: create and initialise array
On Thursday, 20 June 2019 at 01:32:04 UTC, matheus wrote: import std.stdio; import std.array; void main(){ auto s = uninitializedArray!(float[])(100); s[] = 0.0f; writeln(s[0]); } another version: auto arr = new double[ 10 ]; writeln( arr[5] ); // NaN arr.length += 10; writeln( arr[15] ); // NaN imo NaN is useless, weird and unusual coz integrals and pointers are "all bits zeroes" but float and chars are "all bits ones". WTF? its strange that bool.init is false in such case. .init = "all zeroes" can be faster initialize any block of memory. for example array of structs coz u dont need copy struct.init to each element and just fill memory with AVX2 zeroed register (or another fastest hack). with "all zeroes" u can continue work without reinitialization first as arr[15] += 3.14; probably should be added option to compiler. and again module behavior will be different due to this option. NaN/#FF was worst decision. The road to hell is paved with good intentions. or do a poll for the last decision for several months and leave it as it is forever or recompile new versions with zeros. and of course there must be the possibility of increasing the length of the array with a given value.
Re: Elegant way to test if members of array A are present in array B?
On Tuesday, 11 June 2019 at 18:39:38 UTC, KnightMare wrote: probably strstr https://dlang.org/library/core/stdc/string/strstr.html implemented over it. there is a tendency to remove dependency from C-runtime. *FIX* strpbrk https://dlang.org/phobos/core_stdc_string.html#.strpbrk
Re: Elegant way to test if members of array A are present in array B?
On Tuesday, 11 June 2019 at 17:12:17 UTC, Robert M. Münch wrote: Is there a simple and elegant way to do this? Or is just using a foreach(...) with canFind() the best way? not elegant, not simple. for byte/short/ubye/ushort only https://www.strchr.com/strcmp_and_strlen_using_sse_4.2 https://dlang.org/spec/iasm.html probably strstr https://dlang.org/library/core/stdc/string/strstr.html implemented over it. there is a tendency to remove dependency from C-runtime.
need article: How is working D-GC?
please write some explanation about subj. - what exactly it scans? - why it scan data-segment? https://issues.dlang.org/show_bug.cgi?id=15723 https://issues.dlang.org/show_bug.cgi?id=19947 precise GC doesn't help with issues. - maybe add new type like gcpointer or something (making word "pointer" as keyword is not good idea) that must be scanned 100%. some mix of uint/ulong and void* with arithmetic support +=N -=N for bytes offset without any cast. not for @safe. - maybe to make precise gc as option for compiler (not runtime) that will scans only pointer vars, gcpointer and other roots, not the all data segment (no longs, no doubles[5], no long/double fields in structs etc)? at runtime GC has no info about data-segment so its pessimistic and scans all of it (probably. need clarifying article). if make it compile option than compiler/linker can say exactly what should be scanned and what shouldn't. - when I transfer some gcptr to C or another library its only my responsibility to invoke GC.addRoot/addRange or some .holdThisData in case addRoot/addRange has another mean. the point is "dont scan everything, scan what user/compiler point to u". GC is dangerous for now, it should be fixed, nobody will work with such GC at critical/24/7 systems. imo pessimistic gc should be removed at all. in case GC won't be fixed tell us, it will be fair.
Re: D compiler need -nogc witch and document of library also need nogc button
On Tuesday, 11 June 2019 at 14:44:20 UTC, KnightMare wrote: Stroustrup said about C++ (not exactly quote. I translated it from my lang not English): since C and C ++ will be used by the same people on many years, the differences between languages should be either minimal or maximal to minimize the amount mistakes and misunderstandings. so this 2 modes - gc & nogc - of D must follow the same principle. DBC with RC will be new lang. so, will they be very similar or very different?
Re: D compiler need -nogc witch and document of library also need nogc button
On Tuesday, 11 June 2019 at 12:42:03 UTC, Adam D. Ruppe wrote: On Tuesday, 11 June 2019 at 10:24:05 UTC, KnightMare wrote: people who are interested only in betterC/nogc shouldn't see documentation to api that they are not suitable. I've considered doing that before, but it is actually impossible to get right in the general case due to attribute inference. Consider `map`, for example. If you map a nogc function, map is nogc. But if not, it isn't - it depends on what function the user passes to it. So the documentation can not know for sure. imo problem with nogc/betterc is more deeper. lets suppose we already have rcstring class and man want to write func that returns slice of it. char[] someStrProcess(...) { rcstring tmp = "hello" ~ rcreadln; // somehow we got rcstring return tmp[5..$-5]; } with current slise (struct{.ptr, .length}) we have a problem - data of tmp we'll be freed at function exit and current slice will ref to garbage. so compiler should forbid such situation. this is not very well coz people read four current books where the slices were colorfully described, but for some reason a person cannot use them. they will come to forum and will ask another clarifying questions. ok. we should returns some another slice(struct{.rcarray,.offset,.length}) which knows about RC: rcslice someStrProcess(...) { rcstring tmp = "hello" ~ rcreadln; // somehow we got rcstring return tmp[5..$-5]; // I dont want return whole string just part of it // should I return new rcstring as tmp.substr( 5, tmp.length-10 )? // should we lose slices at all? } and this is something new that not described yet. well, it will be. but maybe better write compiler that will returns rcslice as native new style slice char[] that knows about RC? some lang that mix of D and Swift which already used RC as ARC with familiar from book syntax. and tada! we have two different language in one compiler, we have two different RT with one compiler. maybe it will be Phobos and Deimos.
Re: D compiler need -nogc witch and document of library also need nogc button
On Tuesday, 11 June 2019 at 08:05:31 UTC, dangbinghoo wrote: I think that D compiler needs -nogc switch to fully disable gc for a project, LDC -nogc? and document of phobos also needs a friendly way to list-out all @nogc API. +1 people who are interested only in betterC/nogc shouldn't see documentation to api that they are not suitable.
Re: if (X !is null && X.Y !is null) access crash
On Friday, 7 June 2019 at 09:26:52 UTC, Amex wrote: if (X !is null && X.Y !is null) access crash is crashing. imo this code is valid. u can write shorter if (X && X.Y) probably crashed in some another place (X is not objRef but something else.. some code later at same line.. dunno)
Re: Reading Dicom files in Dlang
struct Range { private __vector(ushort) _outer; private size_t _a, _b; this(vector(ushort) data, size_t a, size_t b) { // line 457 _outer = data; _a = a; _b = b; } imo problem is in string private __vector(ushort)_outer; it looks like template(vector!ushort) or function or this is vector from core.simd and replacing it to private long _outer; fix the problem paste code imebra.d and imebra_im.d to someplace
Re: Reading Dicom files in Dlang
whats wrong with answer at SO? https://stackoverflow.com/questions/56278268/reading-dicom-files-in-dlang
Re: Reading .pem files for secured
https://lapo.it/asn1js but dont insert ur certificate there, generate new one for tests
Re: Reading .pem files for secured
The reason is that if I understand the logic of Base64, it's that each character stores 6 bits. My private key .pem has 49 lines of 64 characters worth of Base64, though the sat line isn't full. Anyway, this is data worth of over 18000 bits. The RSA key is supposed to be 4096 bits, so this can't be correct. What am I missing? PEM is a X.509 certificate (whose structure is defined using ASN.1), encoded using the ASN.1 DER (distinguished encoding rules), then run through Base64 encoding and stuck between plain-text anchor lines (BEGIN CERTIFICATE and END CERTIFICATE).
Re: emulate with
imo for parts of names such things will never appear.. names, subnames, overloading.. hell no but I want Kotlin lambdas https://kotlinlang.org/docs/reference/lambdas.html I want more: Function literals with receiver it: implicit name of a single parameter Passing a lambda to the last parameter than will appear https://ask.ericlin.info/post/2017/06/subtle-differences-between-kotlins-with-apply-let-also-and-run/ https://medium.com/tompee/idiomatic-kotlin-lambdas-with-receiver-and-dsl-3cd3348e1235
Re: Linker error: _D6object__T10RTInfoImplVAmA2i48i57ZQyyG2m
widgets.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_D6object__T10RTInfoImplVAmA2i48i57ZQyyG2m". widgets.obj : error LNK2001: Nicht aufgelöstes externes Symbol "_D6object__T10RTInfoImplVAmA2i32i14ZQyyG2m". immutable(ulong[2]) object.RTInfoImpl!([48, 57]).RTInfoImpl immutable(ulong[2]) object.RTInfoImpl!([32, 14]).RTInfoImpl through writeln( demangle("_D6object__T10RTInfoImplVAmA2i48i57ZQyyG2m")); writeln( demangle("_D6object__T10RTInfoImplVAmA2i32i14ZQyyG2m"));
Re: 1 - 17 ms, 553 ╬╝s, and 1 hnsec
Why not simply 17.5531 ms ("%.4f ms") to get rid of the non-ASCII µ prefix? fwiw I like this solution for the output. It is very clear to me. +1 and without space 17.5531ms
Re: How to "Clear the Screen" for Windows Command Processor? (Windows 10)
try next: spawnShell( "cls" ).wait;
Re: how to define infix function
u can use infix function with 1arg without any parentheses. UPD with 2args arg1 `infix func` arg2 latter I told about UFCS with 1arg `UFCS func` arg1
Re: how to define infix function
On Saturday, 2 June 2018 at 22:01:02 UTC, Ali Çehreli wrote: On 06/02/2018 02:44 PM, greatsam4sure wrote: > is it possible to define infix function in D > 3.min(5)// 3: where min is a function, works in D > 3 min 5 // does not work. This is called universal function call syntax (UFCS) in D. Ali UFCS is not same as infix functions. infix allow to u write code like: 1)for (i in 0 to 10 step 2) // `in`(can be keyword too), `to` and `step` can be some functions that change range or something 2) auto shiftedRes = someVar shr 13; // `shr` is infix function too u can use infix function with 1arg without any parentheses. why this need? how it can be useful? look at Kotlin lang. pure functional programming. it can be useful for code looks like LINQ(.NET): DB, UI... and I think UFCS should be improved too: function with 1arg can be written without parenthesis too. for example some declarations: class Task { .. }; Task asyncRead( File file ) { .. } T await!(T)( Task task ) { .. } we can use await like: auto buf = asyncRead( file ).await(); or auto buf = await( asyncRead( file )); // I like spaces between fn-names and args but more clear IMO: auto buf = await asyncRead( file ); // less parenthesis more improvements: 1) see Kotlin passing lambda as last parameter https://kotlinlang.org/docs/reference/lambdas.html#passing-a-lambda-to-the-last-parameter 2) Kotlin/when with pattern matching. dont need change current `switch` instruction. and we can make `when` as expression (look Kotlin samples) 3) scope functions https://kotlinlang.org/docs/reference/scope-functions.html with(button) { text = "hello"; background = Colors.Yellow; } text & background are props of some Button class for instance button. {} is a lambda as last arg
Re: precise GC
IMO need more explanations about precise-GC and cases where behavior of precise and conservative same and differs
Re: precise GC
/* English is not my native, and I tried to use Google translate. I hope u will understand subtleties of questions */ For precise-GC: 3) closures: do the closures have any internal types that helps to GC or are they (full closure memory block) scanned as in the conservative mode? 4) associative arrays: SomeTypeWithRefsToClasses[string] any pair will be allocated at some memory block [hash, key, value] as I imagine. Will be precise-GC scan at every pair block only some fields of SomeTypeWithRefsToClasses or full [pair-block]? will be scanned string-key memory block: span-struct and\or chars data?
precise GC
As I understood conservative-GC scans all allocated memory blocks for false pointers. In other hand precise-GC scans only explicit memory blocks that contains (objects of types that contains) pointers/refs or "muddy" types (void, void[]...). For example, we have some rooted memory block as auto rooted = new long[1_000_000]; 1) conservative-GC will scan it for false pointers every GC-cycle. is it true? 2) precise-GC will NOT scan it at all. is it true?