Re: How to loop through characters of a string in D language?

2021-12-08 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote: Let's say I want to skip characters and build a new string. The string example to loop/iterate: ``` import std.stdio; void main() { string a="abc;def;ab"; } ``` The character I want to skip: `;` Expected result: ``` abcdefab

Re: How to imporve D-translation of these Python list comprehensions ?

2018-01-15 Thread Biotronic via Digitalmars-d-learn
On Monday, 15 January 2018 at 19:05:52 UTC, xenon325 wrote: I think, most clear code would be with tripple `foreach`, so I'll go with that. But probably someone will come up with something better and range-ier. I will admit clarity has suffered, but I like the brevity: import std.json :

Re: How do I set a class member value by its name in a string?

2017-12-27 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 21:42:53 UTC, Mengu wrote: On Wednesday, 27 December 2017 at 21:39:49 UTC, Mengu wrote: On Wednesday, 27 December 2017 at 20:54:17 UTC, bitwise wrote: [...] there's also a simple workaround for fields with the same type: https://run.dlang.io/is/dsFajq

Re: BitArray shift left/right confusion.

2017-12-27 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 27 December 2017 at 18:08:19 UTC, Bastiaan Veelo wrote: I suppose the following is not a bug, but confusing it is: ``` void main() { import std.stdio; import std.bitmanip; BitArray ba = [1, 1, 1, 1, 1, 1, 1, 1]; writeln(ba);// [1, 1, 1, 1, 1, 1, 1, 1]

Re: Tuple Array Sorting

2017-12-15 Thread Biotronic via Digitalmars-d-learn
On Friday, 15 December 2017 at 17:24:33 UTC, Vino wrote: Hi Biotronic, I was able to find a solution using container array and also date formatting, below is the code, please do let me know if you find any issue, as i have tested the script and it is working as expected. Program: import

Re: overload

2017-12-15 Thread Biotronic via Digitalmars-d-learn
On Thursday, 14 December 2017 at 22:47:15 UTC, dark777 wrote: I know that this community is not from c ++, but for some time I studied how to do overload of ostream operators in c ++ and I even managed to get to this result, I got to this result in another post done here but I did not

Re: Tuple Array Sorting

2017-12-12 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 15:19:35 UTC, Vino wrote: import std.algorithm: filter, map, sort; import std.container.array; import std.file: SpanMode, dirEntries, isDir ; import std.stdio: writefln; import std.typecons: Tuple, tuple; import std.datetime.systime: SysTime; void main () { auto

Re: operator overload

2017-12-12 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 16:54:17 UTC, Biotronic wrote: There is no way in C++ to set the format the way you want it. If you want binary output, you need to call a function like your binario function. Of course this is not entirely true - there is a way, but it's ugly and probably not

Re: operator overload

2017-12-12 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 12 December 2017 at 15:52:09 UTC, dark777 wrote: I know that this community is not of c ++, but some time I have been studying how to do overload of ostream operators in c ++ and I even managed to get to this result but the same is not converting to binary only presents zeros as

Re: Tuple Array Sorting

2017-12-11 Thread Biotronic via Digitalmars-d-learn
On Monday, 11 December 2017 at 19:46:04 UTC, Vino wrote: import std.algorithm; import std.container.array; import std.file: SpanMode, dirEntries, isDir ; import std.stdio: writefln, writeln; import std.typecons: Tuple, tuple; import std.range: chain; void main () { auto FFs =

Re: Tuple Array Sorting

2017-12-11 Thread Biotronic via Digitalmars-d-learn
On Monday, 11 December 2017 at 15:33:08 UTC, Vino wrote: On Monday, 11 December 2017 at 15:15:47 UTC, Biotronic wrote: On Monday, 11 December 2017 at 14:52:35 UTC, Vino wrote: Example Program and Output import std.algorithm: filter, map, sort; import std.container.array; import std.file:

Re: Tuple Array Sorting

2017-12-11 Thread Biotronic via Digitalmars-d-learn
On Monday, 11 December 2017 at 15:33:08 UTC, Vino wrote: I tired that but no luck, below is the output, in your code you have one folder "auto folders = ["D:\\Dev"];" if you have multiple folder then output is not sorted. Works on my machine. Of course, since time toSimpleString returns

Re: Tuple Array Sorting

2017-12-11 Thread Biotronic via Digitalmars-d-learn
On Monday, 11 December 2017 at 14:52:35 UTC, Vino wrote: Example Program and Output import std.algorithm: filter, map, sort; import std.container.array; import std.file: SpanMode, dirEntries, isDir ; import std.range: chain; import std.stdio: writefln; import std.typecons: Tuple, tuple; void

Re: Optimizing a bigint fibonacci

2017-12-06 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 10:16:16 UTC, helxi wrote: On Wednesday, 6 December 2017 at 10:00:48 UTC, Biotronic wrote: AliasSeq!(a, b) = tuple( a * (2*b - a), a*a + b*b); [...] Nice. But why the AliasSeq? Just playing around a bit. The alternative is to

Re: Optimizing a bigint fibonacci

2017-12-06 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:12:08 UTC, helxi wrote: This is question not directly related to language concepts, it's got more to do with the application. I would appreciate if anyone would point to me how I could optimize this bit of code Here's my version:, based on fast squaring:

Re: Sort characters in string

2017-12-06 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 08:59:09 UTC, Fredrik Boulund wrote: string word = "longword"; writeln(sort(word)); But that doesn't work because I guess a string is not the type of range required for sort? Yeah, narrow (non-UTF-32) strings are not random-access, since characters like 

Re: cannot deduce template lambda from argument

2017-12-06 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 5 December 2017 at 23:01:43 UTC, aliak wrote: immutable lambda(T) = (T n) => n * n; Generally, you'd want to write alias lambda = n => n * n; instead. That said, I don't see any reason why your syntax shouldn't work, and would argue it's a bug. Please file it in Bugzilla.

Re: Turn a float into a value between 0 and 1 (inclusive)?

2017-11-21 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 21 November 2017 at 09:21:29 UTC, Chirs Forest wrote: I'm interpolating some values and I need to make an (elapsed_time/duration) value a float between 0 and 1 (inclusive of 0 and 1). The elapsed_time might be more than the duration, and in some cases might be 0 or less. What's the

Re: Missing return value error not present with template

2017-11-15 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 15 November 2017 at 08:43:01 UTC, Tony wrote: Error: function test_warnings.MyClass.SomeMethod has no return statement, but is expected to return a value of type int but if I make it a template class: class MyClass(T) { there is no compile error. I don't know why the error

Re: Disabled and enabled copy constructors and .dup

2017-10-24 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 24 October 2017 at 11:37:42 UTC, Per Nordlöw wrote: On Tuesday, 24 October 2017 at 07:56:34 UTC, Biotronic wrote: struct SuppressPostblit(T) { // Disguise T as a humble array. private ubyte[T.sizeof] _payload; ... A bit too hackish for my taste, but does the job still.

Re: Disabled and enabled copy constructors and .dup

2017-10-24 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 24 October 2017 at 07:33:43 UTC, Per Nordlöw wrote: If I have a `struct X` (container in my case) with disabled copying (postblit) and instead a .dup property, is it somehow possible, unsafe or not, to have `X` as a member of another `struct Y` with an enabled copy constructor

Re: Skynet 1M Fiber microbenchmark in D

2017-10-18 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 12:32:31 UTC, Nordlöw wrote: Further, are we forced to use the GC for Fiber allocation or can a sub-class of Fibers implement its own allocation strategy? Afraid it's set in stone. Now, it doesn't actually use the GC for allocating the stack memory, instead

Re: Skynet 1M Fiber microbenchmark in D

2017-10-18 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 11:34:57 UTC, Nordlöw wrote: Another thing...how should the synchronization between the fibers figure out when the total number of fibers have reached one million?...via an atomic counter fed by reference to the constructor...or are there better ways? Because I

Re: Making template instantiations more lazy

2017-10-18 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 10:55:49 UTC, Per Nordlöw wrote: On Wednesday, 18 October 2017 at 10:36:41 UTC, Per Nordlöw wrote: Yeah I've thought of that. I still would like to have it built-in to the compiler. Would such a change cause any serious breakage? Seems unlikely - when did

Re: Skynet 1M Fiber microbenchmark in D

2017-10-18 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 11:01:56 UTC, Per Nordlöw wrote: On Wednesday, 18 October 2017 at 09:01:30 UTC, Per Nordlöw wrote: Creates an actor (goroutine, whatever), which spawns 10 new actors, each of them spawns 10 more actors, etc. until one million actors are created on the final

Re: Making template instantiations more lazy

2017-10-18 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 18 October 2017 at 09:56:33 UTC, Nordlöw wrote: On Wednesday, 18 October 2017 at 09:32:39 UTC, Jonathan M Davis wrote: On Wednesday, October 18, 2017 09:13:47 Per Nordlöw via Digitalmars-d-learn wrote: Are there any nearby plans to make more template instantiations (especially

Re: testing if data is allocated on the stack or heap

2017-10-18 Thread Biotronic via Digitalmars-d-learn
It's worth pointing out, btw, that the main reason for this code is to help drug diagnose his or her problem, not to be the be-all, end-all of stack identifying functions. :) It will of course not correctly identify pointers to variables on other threads' stacks, and fiber stacks probably

Re: testing if data is allocated on the stack or heap

2017-10-18 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 23:59:19 UTC, Steven Schveighoffer wrote: On 10/17/17 7:32 PM, flamencofantasy wrote: On Tuesday, 17 October 2017 at 17:27:17 UTC, Biotronic wrote: On Tuesday, 17 October 2017 at 15:33:02 UTC, drug wrote: [...] I have very little knowledge about sbrk, so

Re: testing if data is allocated on the stack or heap

2017-10-17 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 17 October 2017 at 15:33:02 UTC, drug wrote: My code fails and I guess the reason is I have a slice to data in the stack and it becomes garbage in some moment. So I need a way to check where data is placed. Is it right that it can be done in linux using `sbrk` so that if the addr

Re: partiallyQualifiedName?

2017-10-17 Thread Biotronic via Digitalmars-d-learn
On Monday, 16 October 2017 at 23:56:00 UTC, Nicholas Wilson wrote: using fullyQualifiedName [here] (https://github.com/libmir/dcompute/blob/master/source/dcompute/driver/ocl/util.d#L120) leads to a large compilation slowdown, but I only need it to disambiguate up to the module level i.e. so

Re: what operator(s) should I overload to prevent this?

2017-10-16 Thread Biotronic via Digitalmars-d-learn
On Monday, 16 October 2017 at 12:00:13 UTC, drug wrote: I refactored `MyStructure` added own implementation of malloced array based on pureRealloc/pureFree instead of dynamic array I used before and now I have error: Error: cannot implicitly convert expression get(msg.getData()) of type

Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?

2017-10-13 Thread Biotronic via Digitalmars-d-learn
On Friday, 13 October 2017 at 10:35:56 UTC, Jack Applegame wrote: Compiler creates struct on the stack and silently (without postblitting and destruction old object) moves it to another address. Is it normal? I don't think so. It is. Structs have no identity, and the compiler/GC/whatever is

Re: For fun: Expressive C++ 17 Coding Challenge in D

2017-10-05 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 4 October 2017 at 19:20:12 UTC, Jesse Phillips wrote: On Wednesday, 4 October 2017 at 15:26:02 UTC, Ali Çehreli wrote: On 10/04/2017 02:04 AM, Biotronic wrote: ... Hey where is the list of features used e.g: ranges, ufcs... Features used: D. But sure, added them to the gist:

Re: For fun: Expressive C++ 17 Coding Challenge in D

2017-10-04 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 4 October 2017 at 09:04:58 UTC, Biotronic wrote: Since the code uses ranges though, a simple replacement of readText with an mmapped equivalent should enable humongous file support with no other code change required. Drop-in replacement for readText: struct MmText { import

Re: How to implement `isTemplate` traits?

2017-10-04 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 4 October 2017 at 09:32:31 UTC, drug wrote: I need to separate templates: ``` foreach(member; __traits(allMembers, V)) { static if (__traits(compiles, { auto _val = &__traits(getMember, value, member); }) { // a template needs to be instantiated to be addressable, so

Re: For fun: Expressive C++ 17 Coding Challenge in D

2017-10-04 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 19:25:56 UTC, Ali Çehreli wrote: Found on Reddit: https://www.reddit.com/r/programming/comments/740617/the_expressive_c17_coding_challenge/ How would you do it in D? Ali P.S. You can ignore the following note from the challenge text; I don't think it applies

Re: Struct bug?

2017-10-02 Thread Biotronic via Digitalmars-d-learn
On Monday, 2 October 2017 at 09:34:29 UTC, Andrea Fontana wrote: Anyway: you cant put a default destructor on struct True. In which case you should either @disable this() (which presents its own set of issues) or hide b behind a @property function, something like: struct S { B _b;

Re: Struct bug?

2017-10-02 Thread Biotronic via Digitalmars-d-learn
On Monday, 2 October 2017 at 08:47:47 UTC, Andrea Fontana wrote: Why this code doesn't write two identical lines? https://dpaste.dzfl.pl/e99aad315a2a Andrea A reduced example of where it goes wrong: class B {} struct A { B b = new B; } unittest { A a1, a2; assert(a1 == a2); }

Re: Is it possible to avoid call to destructor for structs?

2017-09-24 Thread Biotronic via Digitalmars-d-learn
On Sunday, 24 September 2017 at 18:46:15 UTC, Haridas wrote: Also consider the following code. Please let me know if I am doing the right thing for dynamic arrays. My hack seems to have the desired effect on shutting down the destructor. Is this hack legal use of D? Can you please guide me

Re: Adding empty static this() causes exception

2017-09-13 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 12 September 2017 at 19:59:52 UTC, Joseph wrote: The compiler shouldn't arbitrarily force one to make arbitrary decisions that waste time and money. Like having a type system? Having to do *cast(int*) to interpret a string as an int isn't strictly necessary, and wastes dev time

Re: Adding empty static this() causes exception

2017-09-12 Thread Biotronic via Digitalmars-d-learn
The simplest example of a cycle is probably this: module A; import B; int n1 = 17; static this() { n1 = n2; } // module B; import A; int n2 = 42; static this() { n2 = n1; } What's the value of n1 and n2 after module constructors are run? Since both module constructors can run

Re: Adding empty static this() causes exception

2017-09-12 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 12 September 2017 at 09:11:20 UTC, Joseph wrote: I have two nearly duplicate files I added a static this() to initialize some static members of an interface. On one file when I add an empty static this() it crashes while the other one does not. The exception that happens is

Re: Anonymous nogc class

2017-09-08 Thread Biotronic via Digitalmars-d-learn
On Friday, 8 September 2017 at 12:32:35 UTC, Jiyan wrote: On Friday, 8 September 2017 at 06:37:54 UTC, Biotronic wrote: On Thursday, 7 September 2017 at 23:40:11 UTC, Jiyan wrote: [...] Sadly, even std.typecons.scoped isn't currently @nogc: https://issues.dlang.org/show_bug.cgi?id=13972

Re: Anonymous nogc class

2017-09-08 Thread Biotronic via Digitalmars-d-learn
On Thursday, 7 September 2017 at 23:40:11 UTC, Jiyan wrote: Hey, wanted to know whether it is possible to make anonymous nogc classes: interface I { public void ap(); } void exec(I i) { i.ap; } // now execute, but with something like `scope` exec( new class I { int

Re: New programming paradigm

2017-09-07 Thread Biotronic via Digitalmars-d-learn
On Thursday, 7 September 2017 at 16:55:02 UTC, EntangledQuanta wrote: Sorry, I think you missed the point completely... or I didn't explain things very well. I don't think I did - your new explanation didn't change my understanding at least. This indicates I'm the one who's bad at

Re: New programming paradigm

2017-09-07 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 6 September 2017 at 23:20:41 UTC, EntangledQuanta wrote: So, no body thinks this is a useful idea or is it that no one understands what I'm talking about? Frankly, you'd written a lot of fairly dense code, so understanding exactly what it was doing took a while. So I sat down

Re: Template substitution for function parameters

2017-09-03 Thread Biotronic via Digitalmars-d-learn
On Saturday, 2 September 2017 at 01:41:14 UTC, Nicholas Wilson wrote: On Friday, 1 September 2017 at 11:33:15 UTC, Biotronic wrote: On Friday, 1 September 2017 at 10:15:09 UTC, Nicholas Wilson wrote: So I have the following types struct DevicePointer(T) { T* ptr; } struct Buffer(T) {

Re: 24-bit int

2017-09-02 Thread Biotronic via Digitalmars-d-learn
On Saturday, 2 September 2017 at 00:43:00 UTC, Nicholas Wilson wrote: On Friday, 1 September 2017 at 22:10:43 UTC, Biotronic wrote: struct int24 { ubyte[3] _payload; this(int x) { value = x; } ... } You may also want to put an align(1) on it so that you dont waste

Re: get parameter names

2017-09-01 Thread Biotronic via Digitalmars-d-learn
On Friday, 1 September 2017 at 20:58:20 UTC, EntangledQuanta wrote: template(A, B...) { auto foo(C...)(C c) { ... get c's parameter names, should be alpha, beta } } foo!(., .)(alpha, beta) I need the actual identifiers passed to foo. I can get the types(obviously C) but when

Re: 24-bit int

2017-09-01 Thread Biotronic via Digitalmars-d-learn
On Friday, 1 September 2017 at 19:39:14 UTC, EntangledQuanta wrote: Is there a way to create a 24-bit int? One that for all practical purposes acts as such? This is for 24-bit stuff like audio. It would respect endianness, allow for arrays int24[] that work properly, etc. I haven't looked at

Re: Template substitution for function parameters

2017-09-01 Thread Biotronic via Digitalmars-d-learn
On Friday, 1 September 2017 at 10:15:09 UTC, Nicholas Wilson wrote: So I have the following types struct DevicePointer(T) { T* ptr; } struct Buffer(T) { void* driverObject; T[] hostMemory; } and a function auto enqueue(alias k)(HostArgsOf!k) { ... } where k would be a function like

Re: Bug in D!!!

2017-09-01 Thread Biotronic via Digitalmars-d-learn
On Thursday, 31 August 2017 at 15:48:12 UTC, EntangledQuanta wrote: On Thursday, 31 August 2017 at 10:34:14 UTC, Kagamin wrote: On Thursday, 31 August 2017 at 00:49:22 UTC, EntangledQuanta wrote: I've already implemented a half ass library solution. It can be improved alot. Then, by all

Re: Missing array element

2017-08-30 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 30 August 2017 at 06:16:16 UTC, Vino.B wrote: On Tuesday, 29 August 2017 at 18:39:03 UTC, Ali Çehreli wrote: https://dlang.org/phobos/std_algorithm_setops.html#.setDifference I tried the setDifference but does seem to be working as expected From the documentation of

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 12:50:07 UTC, Suliman wrote: MyStruct[] is actually a struct similar to this: struct MyStruct[] { MyStruct* ptr; size_t length; } That struct is placed on the stack, but the data it points to, via the ptr field, is heap allocated. What is struct? Just

Re: If structures places data to stack why we do not getting stackoverflow on array of structures?

2017-08-16 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 07:39:01 UTC, Suliman wrote: On the heap, unless you are allocating it via e.g. alloca. If struct MyStruct { int x; int y; } MyStruct mystruct; is located on stack, why: MyStruct [] mystructs; should located on heap? MyStruct[] is actually a struct

Re: Why does stringof not like functions with arguments?

2017-08-09 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 9 August 2017 at 01:39:07 UTC, Jason Brady wrote: Why does the following code error out with: app.d(12,10): Error: function app.FunctionWithArguments (uint i) is not callable using argument types () Like Olivier said, stringof expects a valid expression. There are a few other

Re: Function with static array as parameter

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 12:20:11 UTC, Miguel L wrote: What is the best way in D to create a function that receives a static array of any length? You will need to use templates: void foo(size_t N)(int[N] arr) { } -- Biotronic

Re: Foreign threads in D code.

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 12:08:35 UTC, Jacob Carlborg wrote: On 2017-07-12 11:28, Biotronic wrote: That's basically what I tried to say It wasn't very clear to me at least. Yeah, I see it in retrospect. "might collect memory that the thread is referencing on the stack or in non-GC

Re: Struct Constructor Lazy

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 12:02:37 UTC, Jiyan wrote: Thank you, one last question: If i declare the parameter as ref i, then there shouldnt be any overhead wouldnt it? Thanks :) That would be basically the exact equivalent - instead of passing an int, you'll be passing a pointer. --

Re: Struct Constructor Lazy

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 11:34:45 UTC, Jiyan wrote: Hey, yes i did but to be honest i used dmd in debug version. The thing about the static one, is that it creates a local object A isnt that a performance issue itself - or am i wrong - im confused actually :P? Debug = no optimization.

Re: Struct Constructor Lazy

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 11:00:54 UTC, Jiyan wrote: Hey there:) i want to know whether the following is somehow possible: structs dont have default constructors, i know so: struct A { int field; this(int i){field = getDataFromFile("file.txt");} } A instance = A(0); Here comes my issue:

Re: Foreign threads in D code.

2017-07-12 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 09:10:07 UTC, Jacob Carlborg wrote: On 2017-07-11 08:18, Biotronic wrote: If DRuntime is not made aware of the thread's existence, the thread will not be stopped by the GC, and the GC might collect memory that the thread is referencing on the stack or in non-GC

Re: Foreign threads in D code.

2017-07-11 Thread Biotronic via Digitalmars-d-learn
On Monday, 10 July 2017 at 20:03:32 UTC, Igor Shirkalin wrote: Hello! I have written some D code that I need to link to :C++ huge project. Let it be just one function that uses GC. The question is: if C++ code creates several threads and runs this :D function simultaneously, will GC work

Re: Implementing interfaces using alias this

2017-06-16 Thread Biotronic via Digitalmars-d-learn
On Thursday, 15 June 2017 at 18:49:58 UTC, Jesse Phillips wrote: wrap!IDuck Ah, so it does exist in Phobos. I thought it should be there, but didn't find it. Thanks! -- Biotronic

Re: Implementing interfaces using alias this

2017-06-15 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 09:34:27 UTC, Balagopal Komarath wrote: void main() { Test!Duck d; } As has been pointed out at length by others here, it's simply not how alias this is intended to work. I do see some arguments in favor of working that way, but I'm not sure what's the

Re: O(1) sum

2017-06-12 Thread Biotronic via Digitalmars-d-learn
On Monday, 12 June 2017 at 01:36:04 UTC, Stefan Koch wrote: On Monday, 12 June 2017 at 01:02:58 UTC, helxi wrote: Is it possible to sum an array in O(1)? No. If you want to sum the elements you have to at-least look at all the elements. So it'll always be O(N). it's the best you can do.

Re: import statement placement

2017-06-07 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 12:39:07 UTC, Russel Winder wrote: Are there any idiom rules as to where to put import statements in D? In Python they can go anywhere but PEP-8 suggests they should all go at the top of a file, just after the module documentation string. I don't know if there

Re: Can assumeSafeAppend() grab more and more capacity?

2017-06-07 Thread Biotronic via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 05:43:06 UTC, ag0aep6g wrote: [snip] It seems to me this is a topic worthy of a more in-depth article. If only I felt up to that. :p When you create a slice 'a' in D (with the current GC and druntime, at least), what happens behind the scenes is the allocator

Re: How to cleanup array of structs?

2017-06-02 Thread Biotronic via Digitalmars-d-learn
On Friday, 2 June 2017 at 13:32:02 UTC, Suliman wrote: I remember that there was topic about remobing data from struct/arrays of structs. But I do not remember what is idiomatic way to do it, and can't google it. something like: struct MyTrack { ulong id; string

Re: purity question

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 13:45:07 UTC, Rene Zwanenburg wrote: On Tuesday, 30 May 2017 at 11:34:52 UTC, ketmar wrote: If malloc were marked as pure, wouldn't that mean it must return the same pointer every time you call it with the same size? of course. but D "pure" is not what other world

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:46:12 UTC, Andrew Edwards wrote: On Tuesday, 30 May 2017 at 10:37:58 UTC, Biotronic wrote: On Tuesday, 30 May 2017 at 10:31:24 UTC, Daniel Kozak wrote: import std.traits : fqn = fullyQualifiedName; Darnit. I just googled the template and got a result talking

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:31:24 UTC, Daniel Kozak wrote: import std.traits : fqn = fullyQualifiedName; Darnit. I just googled the template and got a result talking about fqn!T. So yeah - this code: import std.traits; pragma(msg, fullyQualifiedName!ImVec2); pragma(msg,

Re: Error: func(const(A) a) is not callable using argument types (const(A)

2017-05-30 Thread Biotronic via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 10:09:50 UTC, Andrew Edwards wrote: What does that even mean? Scenario: bool func(const ImVec2 label_size) { return true; } void main() { //first attempt: const ImVec2 label_size = CalcTextSize(label.ptr, null, true); //Error: cannot implicitly

Re: Code improvement for DNA reverse complement?

2017-05-22 Thread Biotronic via Digitalmars-d-learn
On Monday, 22 May 2017 at 08:58:24 UTC, biocyberman wrote: @Nicolas Wilson: Your explanation of the enum is clear and very helpful. I can recall to the same technique used in kh_hash in samtools and the associated. With that said, the chars enum is only to 'T' (85) elements. The reason for

Re: Code improvement for DNA reverse complement?

2017-05-22 Thread Biotronic via Digitalmars-d-learn
On Friday, 19 May 2017 at 22:53:39 UTC, crimaniak wrote: On Friday, 19 May 2017 at 12:55:05 UTC, Biotronic wrote: revComp6 seems to be the fastest, but it's probably also the least readable (a common trade-off). Try revComp7 with -release :) string revComp7(string bps) { char[] result =

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread Biotronic via Digitalmars-d-learn
On Friday, 19 May 2017 at 12:21:10 UTC, biocyberman wrote: 1. Why do we need to use assumeUnique in 'revComp0' and 'revComp3'? D strings are immutable, so if I'd created the result array as a string, I couldn't change the individual characters. Instead, I create a mutable array, change the

Re: Code improvement for DNA reverse complement?

2017-05-19 Thread Biotronic via Digitalmars-d-learn
On Friday, 19 May 2017 at 07:29:44 UTC, biocyberman wrote: I am solving this problem http://rosalind.info/problems/revc/ as an exercise to learn D. This is my solution: https://dpaste.dzfl.pl/8aa667f962b7 Is there some D tricks I can use to make the `reverseComplement` function more concise

Re: What's a good wat to trunctate a time point

2017-05-10 Thread Biotronic via Digitalmars-d-learn
On Friday, 5 May 2017 at 09:14:21 UTC, Biotronic wrote: Here's an implementation that supports start of year, month, week, day, hour, minute and second. Works for DateTime and SysTime. Not heavily tested (all tests included): As the last sentence says, there were holes in the testing,

Re: What's a good wat to trunctate a time point

2017-05-05 Thread Biotronic via Digitalmars-d-learn
On Friday, 5 May 2017 at 08:02:15 UTC, Dukc wrote: I have a time point, be it SysTime or DateTime, whatever. I want to trunctate it to weeks, eg. I want it to become the first point of time during the week it was representing. What's a good way to do that? Only hacks came to my mind. The

Re: Multiple template alias parameters

2015-05-08 Thread Biotronic via Digitalmars-d-learn
On Friday, 8 May 2015 at 21:56:56 UTC, Brian Schott wrote: Allowing template Tem(alias Args ...) syntax would let me trace multiple variables at once. Actually, this already works: void traceVars(alias T, U...)() { import std.stdio : writeln; writeln(T.stringof, : , T); static if