Re: Surprising interaction of tuples and slicing

2020-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 5/7/20 8:33 AM, Ben Jones wrote:> I was doing some metaprogramming where I wanted to make a slice of a type: [...] > alias Ts = AliasSeq!int; > pragma(msg, Ts); > alias Tsa = Ts[]; > pragma(msg, Tsa); > //prints (int), (int) > > which confused me until I realized that the [] was slicing the

Re: Error running concurrent process and storing results in array

2020-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 5/5/20 8:41 PM, data pulverizer wrote:> On Wednesday, 6 May 2020 at 03:33:12 UTC, Mathias LANG wrote: >> On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: > Is there something I need to do to wait for each thread to finish > computation? thread_joinAll(). I have an example

Re: Idomatic way to guarantee to run destructor?

2020-05-04 Thread Ali Çehreli via Digitalmars-d-learn
On 5/4/20 2:47 AM, Olivier Pisano wrote: On Monday, 4 May 2020 at 09:20:06 UTC, Ali Çehreli wrote: On 4/30/20 10:04 AM, Ben Jones wrote:> On Thursday, 30 April 2020 at 16:55:36 UTC, Robert M. Münch wrote: > I think you want to use scope rather than auto which will put the class > on the stack

Re: Idomatic way to guarantee to run destructor?

2020-05-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/30/20 10:04 AM, Ben Jones wrote:> On Thursday, 30 April 2020 at 16:55:36 UTC, Robert M. Münch wrote: > I think you want to use scope rather than auto which will put the class > on the stack and call its destructor: > https://dlang.org/spec/attribute.html#scope That is correct about

Re: countUntil with negated pre-defined predicate?

2020-05-04 Thread Ali Çehreli via Digitalmars-d-learn
On 5/3/20 2:59 PM, Harry Gillanders wrote:> On Sunday, 3 May 2020 at 12:19:30 UTC, Robert M. Münch wrote: > an `auto ref` parameter[1] in a > function template is essentially a parameter that receives the > argument by reference if the templated type is a value-type, Please replace "a

Re: How can I check if an element is iterable?

2020-05-03 Thread Ali Çehreli via Digitalmars-d-learn
On 5/3/20 1:44 PM, Marcone wrote: On Sunday, 3 May 2020 at 20:11:58 UTC, Adam D. Ruppe wrote: On Sunday, 3 May 2020 at 20:02:09 UTC, Marcone wrote: How can I check if an element is iterable in Dlang? http://dpldocs.info/experimental-docs/std.traits.isIterable.html I don't want to check if

Re: How can I do dmd omite error when if compare two different data types ? (-fpermissive)

2020-05-03 Thread Ali Çehreli via Digitalmars-d-learn
On 5/3/20 4:03 PM, Marcone wrote: In C++ I just use -fpermissive foreach(i; tuple(10, "lemon", false, "John", 1.6, 'c')) {     writeln(i);     if(i == "John") break; // Error } I am not sure I understand your question because it already omits an error. If you're asking how to get

Re: a function like writeln that returns a string rather than writes to a file

2020-05-02 Thread Ali Çehreli via Digitalmars-d-learn
On 5/1/20 7:40 PM, dan wrote:> On Saturday, 2 May 2020 at 02:29:43 UTC, H. S. Teoh wrote: >> On Sat, May 02, 2020 at 02:22:42AM +, dan via Digitalmars-d-learn >> wrote: >>> I'm looking for a function something like writeln or write, but >>> instead of writing to stdout, it writes to a string

Re: Help, what is the code mean?

2020-04-28 Thread Ali Çehreli via Digitalmars-d-learn
On 4/28/20 1:48 PM, Net wrote: > () { ... } (); > > Is there a name of this kind of function in D? unnamed? anonymous? Lambda or anonymous function.[1] Note that the last () is not part of the definition but the execution of the function. This idiom is used for initializing e.g. a const

Re: DConf 2017 Videos

2020-04-24 Thread Ali Çehreli via Digitalmars-d-learn
On 4/24/20 2:11 PM, Steven Schveighoffer wrote:> On 4/24/20 4:24 PM, matheus wrote: > whomever controlled the sociomantic youtube account took down > all the videos. I think it's unintentional because the same thing happened to my Weka account: After I stopped working there, the company

Re: No implicit opOpAssign for structs with basic types?

2020-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/20 8:45 AM, Steven Schveighoffer wrote: >> Yes, sure, but in C++ I don't have to explicitly write this down. It >> just works. IMO that makes a lot of sense as long as all types fit. >> This just looks superfluously. >> > > steves@homebuild:~$ cat test.cpp > struct S > { > float a; >

Re: DMD: Is it possible change compile time errors to runtime errors in Dlang?

2020-03-06 Thread Ali Çehreli via Digitalmars-d-learn
On 3/6/20 5:59 AM, Marcone wrote:> On Friday, 6 March 2020 at 05:31:57 UTC, Mathias Lang wrote: > I'm coming from Python The fact that errors are delayed until run time is a Python deficiency. We accept that deficiency because we also accept claimed benefits that Python brings. If you want

Re: in not working for arrays is silly, change my view

2020-02-29 Thread Ali Çehreli via Digitalmars-d-learn
On 2/29/20 11:38 AM, JN wrote: > assert(1 in [1, 2, 3]); Because you mentioned canFind, I think you want the semantics to be "is there an element with this value." If so, it would be confusing to use the same operator for two different things: For associative arrays, it means "is there an

Re: What's opIndexAssign supposed to return ?

2020-02-25 Thread Ali Çehreli via Digitalmars-d-learn
On 2/25/20 3:02 AM, wjoe wrote:> Lets say I've got 3 overloads of opIndexAssign: > > auto opIndexAssign(T t); > an internet search which didn't find any useful > information. I have examples for non-templatized and templatized versions of opIndexAssign here:

Re: Dynamic array of Cycle buffers of size 2 which use a struct?

2020-02-22 Thread Ali Çehreli via Digitalmars-d-learn
On 2/22/20 2:29 PM, Robert M. Münch wrote: I don't get how I can create a dynamic array of Cycle buffers of size 2 which use a struct.  struct ms {    int a;    int b;  }  ms[2] msBuffer;  alias circularStructBuffersT = typeof(cycle(msBuffer));  circularStructBuffersT[int]

Re: 2D matrix operation (subtraction)

2020-02-21 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/20 12:51 AM, Andre Pany wrote: Hi, I have a 2D double array and I want to subtract from the first column a value, is this possible with matrix operation in D? ``` void main() {     double[][] data = [[0.0, 1.4], [1.0, 5.2], [2.0, 0.8]];     // subtract -2.0 from the first column

Re: Regex split ignoore empty and whitespace

2020-02-20 Thread Ali Çehreli via Digitalmars-d-learn
On 2/20/20 4:46 PM, Ali Çehreli wrote: >auto range = std.regex.splitter!(No.keepSeparators)(l, > ctRegex!`[\s-\)\(\.]+`); After realizing that No.keepSeparators is the default value anyway, I tried 'split' and it worked the way you wanted. So, perhaps all you needed was that extra '+' in

Re: Regex split ignoore empty and whitespace

2020-02-20 Thread Ali Çehreli via Digitalmars-d-learn
On 2/20/20 2:02 PM, AlphaPurned wrote:> std.regex.split(l, ctRegex!`[\s-\)\(\.]`); > > I'm trying too split a string on spaces and stuff... but it is returning > empty strings and other matches(e.g., ()). > > I realize I can delete afterwards but is there a direct way from split > or ctRegex?

Re: Get compilation errors within opDispatch?

2020-02-17 Thread Ali Çehreli via Digitalmars-d-learn
On 2/17/20 8:41 AM, cc wrote: Is there any way to see the compilation errors that occurred within an opDispatch template? struct Foo { void opDispatch(string s, SA...)(SA sargs) {     literally anything; } } Foo foo; foo.hello(5); Result:  Error: no property `hello` for type

Re: How to refer to different sized static arrays

2020-02-08 Thread Ali Çehreli via Digitalmars-d-learn
On 2/8/20 12:22 AM, Adnan wrote: Just a foreword, this is for learning purposes, hence I am not using the dynamic array or Array!T. I have a structure that maintains a heap allocated sized array inside. struct LifoStack(T) {   T[?] data; } This `data` is manually resized and copied. Thus

Re: Abstract override behaviour

2020-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 2/5/20 8:49 AM, Claudiu wrote: In class "Min" definition I am receiving this error: "cannot implicitly override base class method `IncrementalStat.accumulate` with `Min.accumulate`; add `override` attribute" Andrei's book is a little dated. Here is the errata:

Re: Unexpected result of IsInstanceOf

2020-01-30 Thread Ali Çehreli via Digitalmars-d-learn
On 1/30/20 4:51 PM, Ben Jones wrote: The following result doesn't make sense to me... how does isInstanceOf return false? ``` import std.traits; import std.stdio; import std.typecons; auto f(T)(T t){ return Nullable!T(t); } void main(){     auto f3 = f(3);    

Re: Subrange type

2020-01-28 Thread Ali Çehreli via Digitalmars-d-learn
On 1/28/20 1:55 AM, Herbert wrote: > wow, pragma, pragma was to indicate the type of elements at compile time. > import ... Yes, iota is a Phobos feature, part of a module. > only to declare a subrange type, something so simple and natural Some languages think so. > I could use it in many

Re: Subrange type

2020-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 1/27/20 1:15 PM, Herbert wrote: On Monday, 27 January 2020 at 20:15:33 UTC, Steven Schveighoffer wrote: On 1/27/20 3:06 PM, Herbert wrote: How can I create a subrange type, for example ushort DiceValue {1 ... 6}? D doesn't have a "Range" type like this. But you can use ranges of

Re: How to call 'shared static this()' code of a D shared library?

2020-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 1/17/20 7:53 PM, Adam D. Ruppe wrote: Did you already try rt_init? That should trigger it I was under the impression that the extern (C) function rt_init() would magically be exposed from the library but 'nm' showed no such symbol. So, I ended up exposing a my_init() function, which

Re: How to call 'shared static this()' code of a D shared library?

2020-01-18 Thread Ali Çehreli via Digitalmars-d-learn
On 1/18/20 6:14 AM, Guillaume Piolat wrote: On Saturday, 18 January 2020 at 03:53:43 UTC, Adam D. Ruppe wrote: Did you already try rt_init? That should trigger it Indeed, this is done by runtime initialization. Thank you, Adam and Guillaume. That tells me I've been using druntime

How to call 'shared static this()' code of a D shared library?

2020-01-17 Thread Ali Çehreli via Digitalmars-d-learn
Simply linking my D shared library with foreign code (Python with the help of ctypes in this case) does not work. What function should I call? What about 'shared static ~this()'? And would the answer be different for 'static this()' etc.? Thank you, Ali

Re: lambda alias import

2020-01-17 Thread Ali Çehreli via Digitalmars-d-learn
On 1/17/20 3:04 PM, Petar Kirov [ZombineDev] wrote:> On Friday, 17 January 2020 at 21:40:05 UTC, JN wrote: > I think the problem comes from the way you compile and link your code. I > you compile both modules together like this it should work out: > > dmd -ofresult main.d stuff.d If that's the

Re: range algorithms on container class

2020-01-15 Thread Ali Çehreli via Digitalmars-d-learn
On 1/14/20 8:15 PM, Alex Burton wrote:> On Thursday, 9 January 2020 at 10:26:07 UTC, Jonathan M Davis wrote: >> On Wednesday, January 8, 2020 10:56:20 PM MST rikki cattermole via >> Digitalmars-d-learn wrote: >>> Slicing via the opSlice operator overload is a convention, not a >>> requirement.

Re: books for learning D

2020-01-13 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/20 2:28 AM, mark wrote: I'm just starting out learning D. Andrei Alexandrescu's "The D Programming Language" is 10 years old, so is it still worth getting? (I don't know how much D has changed in 10 years.) Yes, Andrei's book is dated but it offers a great perspective on D and

Re: Multi-threaded sorting of text file

2020-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/3/20 11:51 PM, MGW wrote: Need help: There' s a large text file (hundreds of thousands of lines). How long are the lines? If 1K bytes, 100M would fit in memory just fine. There is a parallel quick sort example on the std.parallelism page: https://dlang.org/phobos/std_parallelism.html

Re: Simple casting?

2019-11-26 Thread Ali Çehreli via Digitalmars-d-learn
On 11/26/19 2:08 PM, Taylor R Hillegeist wrote:> On Tuesday, 26 November 2019 at 16:33:06 UTC, Timon Gehr wrote: >> int[][] y=x.chunkBy!((a,b)=>a==b).map!array.array; > > > how did you know to do that? Ranges don't have elements. They either generate elements according to an algorithm,

Re: How to simulate Window's "Press any key to continue..."

2019-11-22 Thread Ali Çehreli via Digitalmars-d-learn
On 11/21/19 9:10 PM, Mike Parker wrote:> On Friday, 22 November 2019 at 04:45:21 UTC, Mike Parker wrote: > You need to call readf with a character > format string (%c): > > import std.stdio; > void main() > { > writeln("Press any key to continue..."); > > char c; > readf("%c", );

Re: Casting from int to long

2019-11-18 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/19 7:16 AM, Yui Hosaka wrote: gives the output 950, while it should be 100. Looks like a bug. Confirmed with dmd 2.088.0 compiling with -O -m32 on Ubuntu. Ali

Re: Default initialization of static array faster than void initialization

2019-11-08 Thread Ali Çehreli via Digitalmars-d-learn
One correction: I think you mean "using" a default-initialized array is faster (not the initialization itself). Another observation: dmd -O makes both cases slower! Hm? Ali

Re: Using an async buffer

2019-11-07 Thread Ali Çehreli via Digitalmars-d-learn
On 11/07/2019 07:07 AM, bioinfornatics wrote: > Dear, > > I try to use the async buffer describe into std.parallelism > documentation but my test code core dump! I admit I don't fully understand the lifetime issues but removing the "code smell" of the modul-level File object solved the issue

Re: Linker anomalies

2019-11-07 Thread Ali Çehreli via Digitalmars-d-learn
On 11/07/2019 04:14 AM, Luh wrote: > Hey there, > > I figured out some strange behavior ; > > #1 > It seems that the linker doesn't check for the function declared twice > first. It's not the linker but the "compiler" that is concerned about these things. > Instead, it says: > > "Error: class

Re: Alternative to C++ macro in D

2019-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/03/2019 08:55 AM, Vinod K Chandran wrote: > Hi all, > I can do this in C++. > #include > using namespace std ; > > #define end }; > #define log(x) cout << x << endl > #define wait std::cin.get() There is nothing that stops one from using the C++ preprocessor on any text file. For

Re: Documentation: is it intentional that template constraints are displayed after the signature?

2019-11-01 Thread Ali Çehreli via Digitalmars-d-learn
On 11/01/2019 09:33 AM, Paul Backus wrote: > On Friday, 1 November 2019 at 15:29:24 UTC, Ali Çehreli wrote: >> Apparently, it's the version for static arrays. However, I don't think >> the template constraint is doing anything there because if T matches a >> static array (of the form U[n]), then

Re: Documentation: is it intentional that template constraints are displayed after the signature?

2019-11-01 Thread Ali Çehreli via Digitalmars-d-learn
On 11/01/2019 04:09 AM, berni44 wrote: > What I don't understand is the 4th version with two extra parameters. > Here the documentation lacks an explanation, what this is good for. I went to the documentation by clicking "View source code" and scrolled a bit and found this:

Re: Special integer operations

2019-10-28 Thread Ali Çehreli via Digitalmars-d-learn
On 10/28/2019 03:20 PM, IGotD- wrote: I'm trying to find if D has any built in special integer operations like bit reverse, population count, count leading zeroes, count trailing zeroes. https://dlang.org/phobos/core_bitop.html Ali

Re: About the in expression, Why can't use with array.

2019-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/2019 02:25 AM, Dennis wrote: > On Friday, 25 October 2019 at 05:17:35 UTC, Ali Çehreli wrote: >> - Big O is different > > No it isn't. Agreed and I've just realized a benefit of the 'in' operator for arrays, which I haven't heard before. (I don't follow all discussions in detail.)

Re: Eliding of slice range checking

2019-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/2019 05:37 AM, Stefan Koch wrote: just replace x = a[i] with x = a.ptr[i]; That's a neat trick! Ali

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/2019 07:34 AM, Robert M. Münch wrote: > If the compiler is a 1-pass one I see the problem, otherwise one could > first get a "total overview" and create the necessary vtbl entries after > everything is known. Maybe this is not "how a compiler is implemented" > but the problem sounds

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/2019 05:58 AM, lili wrote: > Hi: > In Dlang where is strange design. The in expression can only use to > associative array, why array can not use in expression. In addition to the big O surprise, there is another important issue that may be seen as either for or against supporting

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/2019 10:57 AM, Robert M. Münch wrote: > Unfortunately, member function template instances are never virtual > functions, so you can't override them." > > Is there a reason why these type of functions are not virtual or can't > be made virtual? One practical reason is, the number of

Re: Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

2019-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/2019 10:21 AM, Ali Çehreli wrote:   auto lines = File(fileName, "r").byLineCopy(No.keepTerminator, '\r');   auto result = lines.joiner("-").text; I would normally do the following auto lines = File(fileName, "r").byLineCopy(No.keepTerminator, '\r'); auto result =

Re: Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

2019-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/2019 09:49 AM, Mil58 wrote: On Thursday, 24 October 2019 at 16:21:47 UTC, welkam wrote: On Thursday, 24 October 2019 at 15:27:05 UTC, Mil58 wrote: [...] void main() {     File("data.txt", "r+")     .byLineCopy()     .array()     .each!writeln; } byLineCopy removes the

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-23 Thread Ali Çehreli via Digitalmars-d-learn
On 10/23/2019 02:43 AM, Robert M. Münch wrote: >> Unfortunately, member function template instances are never virtual >> functions, so you can't override them. > > What I don't understand is: > > 1. The RX lib has a member function template and than an instance of it > using type Oberver!E. > >

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/2019 01:23 PM, Robert M. Münch wrote: > The whole code > can be found here: https://pastebin.com/5BTT16Ze That says "private paste" for me. But I think you have a member function template in the base class. Unfortunately, member function template instances are never virtual

Re: How to use classes from another d files

2019-10-22 Thread Ali Çehreli via Digitalmars-d-learn
On 10/22/2019 11:25 AM, Vinod K Chandran wrote: > On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote: >> On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran wrote: >>> Hi all, >>> I am new to D. But some fair experience with vb.net. I was playing >>> with D classes. I

Re: std.algorithm.cmp doesn't seem to support numeric types?

2019-10-16 Thread Ali Çehreli via Digitalmars-d-learn
On 10/16/2019 02:34 PM, Dennis wrote: > Except that e.g. -2 - int.max underflows to int.max suggesting that > int.max < -2. Timon had corrected me on that point a while back, so I had added the following warning at

Re: How can I make a program which uses all cores and 100% of cpu power?

2019-10-11 Thread Ali Çehreli via Digitalmars-d-learn
On 10/10/2019 05:41 PM, Murilo wrote: > I have started working with neural networks and for that I need a lot of > computing power but the programs I make only use around 30% of the cpu, > or at least that is what Task Manager tells me. How can I make it use > all 4 cores of my AMD FX-4300 and

Re: Dynamic Arrays as Stack and/or Queue

2019-10-07 Thread Ali Çehreli via Digitalmars-d-learn
On 10/07/2019 10:11 AM, Just Dave wrote: I need a stack and a queue There is a DoubleEndedQueue example under "Indexing Operators" here: http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opIndexOpAssign It does not have the pop varieties but it should be trivial

Re: Difference between slice[] and slice

2019-09-25 Thread Ali Çehreli via Digitalmars-d-learn
On 09/25/2019 12:06 PM, WhatMeWorry wrote: > I was > assuming that [] meant "the entirety" of the array. Assuming we're talking about D slices, Yes. (It could be a user-defined type with surprisingly different semantics.) > In short, is there anytime that one would want to use "slice[] = >

Re: Looking for a Simple Doubly Linked List Implementation

2019-09-23 Thread Ali Çehreli via Digitalmars-d-learn
On 09/23/2019 01:45 PM, Ron Tarrant wrote: > Well, it turns out, I didn't need a linked list, doubly or otherwise. So, what was it then? Append to an array, sort it, and be happy? :) Ali

Re: Interfaces and templates

2019-09-20 Thread Ali Çehreli via Digitalmars-d-learn
On 09/20/2019 12:02 PM, JN wrote: > import std.stdio; > > interface IWriter > { > void write(U)(U x); > } > > class Foo : IWriter > { > void write(U)(U x, int y) > { > writeln(x); > } > } > > > > void main() > { > } > > Does this code make sense? No. Function

Avoid gratuitous closure allocations

2019-09-20 Thread Ali Çehreli via Digitalmars-d-learn
tl;dr Instead of returning an object that uses local state, return an object that uses member variables. We've discovered one such allocation inside std.format.sformat today during our local meetup[1], started fixing it, and discovered that it has already been fixed by ag0aep6g just 19 days

Re: How'd I store possible types for each item of a list of Variants ?

2019-09-20 Thread Ali Çehreli via Digitalmars-d-learn
On 09/20/2019 01:58 AM, oleobal wrote: > My understanding is D has no dynamic dispatch, That's too general. :) D has dynamic dispatch through virtual functions. I don't understand everything here but I think the 'typeid' expression and the 'TypeInfo' class hierarnhy that it returns can be

Re: Using CSS Data from Within My Code

2019-09-12 Thread Ali Çehreli via Digitalmars-d-learn
On 09/12/2019 02:54 AM, Ron Tarrant wrote: > I thought it was odd having 'q' in front of the opening curly brace... I think my index can be useful in such searches. Both q"" and q{} are there: http://ddili.org/ders/d.en/ix.html Ali

Re: default values depending on type of template variable

2019-09-11 Thread Ali Çehreli via Digitalmars-d-learn
On 09/11/2019 01:35 AM, berni wrote: I'd like to write a template, that takes a different default value depending on the type of a variable. Like this? import std.stdio; void main() { double a = 1e-8; double b = 1e-10; float c = 1e-4; float d = 1e-6; assert(!test(a));

Re: need this for name of type string

2019-09-10 Thread Ali Çehreli via Digitalmars-d-learn
On 09/10/2019 03:32 AM, Andre Pany wrote: > @Foo void method0(){} > > @Foo("abc") void method1(){} The UDA syntax allows both types and an objects. method0 uses Foo type and method1 uses a Foo object. So, if your API allows both, your code that deals with UDA must account for both.

Re: It there a way to get this to compile?

2019-09-09 Thread Ali Çehreli via Digitalmars-d-learn
On 09/09/2019 01:59 PM, Ali Çehreli wrote: > On 09/09/2019 12:08 PM, WhatMeWorry wrote: > > Is this even possible? > > No because there can't be expressions at module scope. Attempting to correct myself: I think only declarations are allowed at module scope. Non-compile-time statements like

Re: It there a way to get this to compile?

2019-09-09 Thread Ali Çehreli via Digitalmars-d-learn
On 09/09/2019 12:08 PM, WhatMeWorry wrote: > Is this even possible? No because there can't be expressions at module scope. > static if(true) > { > int r = 2; > int c = 40; Those are fine. > static foreach(i ; foundations) > { > immutable string brackets = "\033["

Re: Interfacing to C++: Cannot access value from namespace

2019-09-07 Thread Ali Çehreli via Digitalmars-d-learn
On 09/07/2019 03:26 AM, Andrew Edwards wrote: > [1] I did not declare any of the other member variables from the struct, > don't know if this is a source of the problem. Yes, it definitely is a problem. The members are accessed as byte offsets into their objects. Without defining the other

Re: Interfacing to C++: Cannot access value from namespace

2019-09-07 Thread Ali Çehreli via Digitalmars-d-learn
On 09/07/2019 03:26 AM, Andrew Edwards wrote: > float continuallyUpdatedValue; > float continuallyChangingValue; // [1] They mean the same thing for an English speaker but compilers don't know that (yet?). :) Ali

Re: Function Arguments with Multiple Types

2019-09-06 Thread Ali Çehreli via Digitalmars-d-learn
On 09/06/2019 01:46 PM, Bob4 wrote: > Thanks; this works, but I'm not sure why. Where does `T` come from? Well... I assumed this would make you research templates. ;) Here is one resource: http://ddili.org/ders/d.en/templates.html (T) means "this function is for any type; and I call that

Re: Function Arguments with Multiple Types

2019-09-06 Thread Ali Çehreli via Digitalmars-d-learn
On 09/06/2019 01:02 PM, Bob4 wrote: > I feel like it's wrong to rewrite identical functions over and over. Enter templates. :) auto clamp(T)(T value, T mini, T maxi) { if (value >= maxi) { return maxi; } if (value <= mini) { return mini; } return value; } unittest {

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Ali Çehreli via Digitalmars-d-learn
On 09/06/2019 02:14 AM, Andrew Edwards wrote: > I'm seeking some pointers on how to define these in D Here is my attempt: struct Demo { // NOTE: The types and number of elements can be templatized and mixed-in like // mixin (makeMembers!T(N)); float a = 0; float b = 0; float c =

Re: getting rid of immutable (or const)

2019-09-05 Thread Ali Çehreli via Digitalmars-d-learn
On 09/05/2019 12:51 PM, berni wrote: >> int[int] a; >> >> immutable int b = 17; >> a[1] = b; // <-- expecting error here As explained elsewhere, a[1] is a mutable int. That assignment is copying b on top of the element. >> const oldPointer = (1 in a);

Re: getting rid of immutable (or const)

2019-09-05 Thread Ali Çehreli via Digitalmars-d-learn
On 09/05/2019 07:31 AM, berni wrote: > On Thursday, 5 September 2019 at 13:27:55 UTC, drug wrote: >> [...]when you put it into an AA you modify old value > > Why?!? :-o When putting it into an AA it will be copied to a different > place in memory, That's the misunderstanding: The existing object

Re: Input/Output multiple values from function

2019-09-02 Thread Ali Çehreli via Digitalmars-d-learn
On 08/27/2019 10:17 PM, Jabari Zakiya wrote: > I can't do (a, b, c,d) = func1(i) directly. > What do I do to assign the output of func1 to the individual variables? I had some time to play with the following syntax, similar usage of which has been proposed a number of times as a replacement

Re: Is it a bug in std.getopt.config.stopOnFirstNonOption?

2019-08-16 Thread Ali Çehreli via Digitalmars-d-learn
On 08/16/2019 02:07 PM, Andrey Zherikov wrote: But: - if I change line (1) to `auto args = ["app", "--foo", "foo", "--bar", "bar"];` then this code works. - if I remove line (2) then this code works. Yes, it's a bug. Another workaround--which I haven't tested to see whether produces the

Re: How should I sort a doubly linked list the D way?

2019-08-14 Thread Ali Çehreli via Digitalmars-d-learn
On 08/13/2019 03:12 PM, Mirjam Akkersdijk wrote: > For the application I am writing, it makes very much sense to use a DLL. Yes, Dynamically Linked Libraries can be useful. Oh wait... You mean Doubly-Linked List. :o) > I tried setting the length first and iterating through it with `nodes[i]

Re: How should I sort a doubly linked list the D way?

2019-08-13 Thread Ali Çehreli via Digitalmars-d-learn
On 08/13/2019 10:33 AM, Mirjam Akkersdijk wrote: > On Tuesday, 13 August 2019 at 14:04:45 UTC, Sebastiaan Koppe wrote: >> Convert the nodes into an D array, sort the array with nodes.sort!"a.x >> < b.x" and then iterate the array and repair the next/prev pointers. If possible, I would go

Re: filtering a row of a jagged array

2019-08-11 Thread Ali Çehreli via Digitalmars-d-learn
On 08/11/2019 09:43 AM, DanielG wrote: such a simple error You're not alone. We want this bug fixed: https://issues.dlang.org/show_bug.cgi?id=17263 Ali

Re: Question about ubyte x overflow, any safe way?

2019-08-04 Thread Ali Çehreli via Digitalmars-d-learn
On 08/04/2019 11:12 AM, matheus wrote: Hi, The snippet below will produce an "infinite loop" because obviously "ubyte u" will overflow after 255: import std.stdio; void main(){     ubyte u = 250;     for(;u<256;++u){     writeln(u);     } } Question: Is there a way (Flag) to prevent

Re: Meaning of Scoped! ??

2019-07-31 Thread Ali Çehreli via Digitalmars-d-learn
On 07/30/2019 02:33 AM, Ron Tarrant wrote: > With contemporary search engines, it's impossible to search for '!' and > get meaningful results. I recommend this Index section for such cases: http://ddili.org/ders/d.en/ix.html Like most of Phobos, Scoped is not there but the "!, template

Re: Is there a way to adjust lookup paths for modules during compilation?

2019-07-31 Thread Ali Çehreli via Digitalmars-d-learn
On 07/31/2019 10:29 AM, Andrey Zherikov wrote: I want my program to add some directories into module lookup process (like adding -I dmd options). List of directories is known at compile time but the choice of what exact directories to add depends on `-version` parameter. Is there a way to

Re: opEquals when your type occurs on the right hand side of an equality test

2019-07-31 Thread Ali Çehreli via Digitalmars-d-learn
On 07/31/2019 01:03 PM, NonNull wrote: I am creating a specialized bit pattern (secretly represented as a uint) as a struct S, but want to avoid `alias this` to maintain encapsulation excepting where I overtly say. Specifically, I want to avoid making arithmetic and inequalities available for

Re: Help me decide D or C

2019-07-31 Thread Ali Çehreli via Digitalmars-d-learn
n 07/31/2019 12:05 PM, Paul Backus wrote: > I would not recommend D as a beginning language, both because there are > fewer beginner-oriented resources available for it than for C and Python > (the only one I know of is Ali Çehreli's book [1]), and because it's a > bigger, more complicated

Re: Calling / running / executing .d script from another .d script

2019-07-28 Thread Ali Çehreli via Digitalmars-d-learn
On 07/28/2019 05:56 AM, BoQsc wrote: Right now, I'm thinking what is correct way to run another .d script from a .d script. Do you have any suggestions? I can be easier than a shared library solution that Max Haughton described. (None of the following code are compiled.) If you have the

Re: Is betterC affect to compile time?

2019-07-25 Thread Ali Çehreli via Digitalmars-d-learn
On 07/25/2019 05:46 AM, Oleg B wrote: On Thursday, 25 July 2019 at 12:34:15 UTC, rikki cattermole wrote: Those restrictions don't stop at runtime. It's vary sad. What reason for such restrictions? It's fundamental idea or temporary implementation? It looks like a bug to me. Ali

Re: Use C struct declaration without knowing definition

2019-07-24 Thread Ali Çehreli via Digitalmars-d-learn
On 07/24/2019 05:35 PM, Ben Ogles wrote: > Is there a way to use a C header that contains a struct declaration but > no definition? > > For example, the C header may contain: > > typedef struct some_type_s some_type; > > Which is only fully defined in the implementing C file: > > struct

Re: accuracy of floating point calculations: d vs cpp

2019-07-23 Thread Ali Çehreli via Digitalmars-d-learn
On 07/22/2019 08:48 PM, Timon Gehr wrote: > This is probably not your problem, but it may be good to know anyway: D > allows compilers to perform arbitrary "enhancement" of floating-point > precision for parts of the computation, including those performed at > compile time. I think this is

Re: How to use lowerBound and upperBound effectively?

2019-07-02 Thread Ali Çehreli via Digitalmars-d-learn
On 07/02/2019 02:27 AM, A. Bressan wrote: > contrary to C++, lowerBound and > upperBound give the same piece of information because they return > complementary sub-ranges. I don't understand the specific problem but can 'trisect' be useful?

Re: Strange behavior of opEquals for structs

2019-06-19 Thread Ali Çehreli via Digitalmars-d-learn
On 06/19/2019 08:28 AM, harfel wrote: Everything works nicely if I compare the structs directly. Yet when they are used as keys in an associative array, the code throws an exception that I do not understand. You need to define toHash() member function as well:

Re: Cast ptr/len to D-style array

2019-05-03 Thread Ali Çehreli via Digitalmars-d-learn
On 05/02/2019 08:21 PM, James Blachly wrote: On 5/2/19 4:05 PM, ag0aep6g wrote: Just slice the pointer with the length: int* ptr; size_t len; int[] arr = ptr[0 .. len]; Perfect thanks. I searched but without using the magic word "slice" I couldn't find meaningful results.

Re: Question regarding readf

2019-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2019 03:29 PM, Andre Pany wrote: > I wonder wheter std.stdio is missing a readfln function. Which executes > readln, strips the #10#13 characters and then executes formattedRead. > Does that make sense to you? Makes sense but what we are missing is standard streaming (like C++'s

Re: Question regarding readf

2019-04-22 Thread Ali Çehreli via Digitalmars-d-learn
On 04/22/2019 01:45 PM, Andre Pany wrote: Hi, following the example from http://ddili.org/ders/d.en/input.html, I try to read a value from console on windows (powershell and dos console). The code from the example does not work, writeln is never executed. import std; void main() {

Re: Convert array to custom type when passing function argument

2019-04-19 Thread Ali Çehreli via Digitalmars-d-learn
On 04/17/2019 05:21 PM, Stefanos Baziotis wrote: > On Wednesday, 17 April 2019 at 23:44:42 UTC, Adam D. Ruppe wrote: >>explicit Test(const char* foo) {} // this opts out of the cool >> thing above > Actually, I asked initially because in C++ you can do the thing I > described. > I thought

Re: Transparent cast from class to member pointer?

2019-04-15 Thread Ali Çehreli via Digitalmars-d-learn
On 04/14/2019 11:03 AM, Robert M. Münch wrote: struct IM; struct C {  IM *impl; }; int cInit(C* self); class I { C handler; this(){cInit();} } Is there a simple way that I can use handler without the address-of operator and automatically get *impl? Something like: class I {   

Re: Finding Super class from Derived Class at compile time

2019-04-14 Thread Ali Çehreli via Digitalmars-d-learn
On 04/14/2019 10:06 PM, LeqxLeqx wrote: Hello! I have a question regarding attempting to access the super class of a derived class at compile time. BaseClassesTuple and friends: https://dlang.org/phobos/std_traits.html Ali

Re: Templates - What's Up with the template keyword?

2019-04-10 Thread Ali Çehreli via Digitalmars-d-learn
On 04/10/2019 05:07 AM, Ron Tarrant wrote: >> the book's index: >> >> http://ddili.org/ders/d.en/ix.html > Oops! Not at all. One of the most useful parts of the book has been the index section for me. I occasionally search in there... like just yesterday for the positional format specifier

Re: Templates - What's Up with the template keyword?

2019-04-09 Thread Ali Çehreli via Digitalmars-d-learn
On 04/08/2019 05:59 AM, Ron Tarrant wrote: On Monday, 8 April 2019 at 12:40:10 UTC, Adam D. Ruppe wrote: You don't need template keyword for the majority of cases because the compiler lets you do shortcuts. Thanks, Adam. Good to know. (maybe I am looking at the wrong part of the book, it is

Re: Templates - What's Up with the template keyword?

2019-04-09 Thread Ali Çehreli via Digitalmars-d-learn
On 04/08/2019 05:23 AM, Ron Tarrant wrote: > But in "Programming in D," (self, 2009-2018) by Ali Çehreli, there's no > mention of the 'template' keyword in any of his examples. 'template' keyword is introduced here: http://ddili.org/ders/d.en/templates_more.html#ix_templates_more.template I

Re: const of AliasSeq is silently ignored

2019-04-08 Thread Ali Çehreli via Digitalmars-d-learn
On 04/08/2019 12:56 PM, Yuxuan Shui wrote: In this example:     const(AliasSeq!(int, int)) a; I would expect that to mean a type list (int, int) that cannot be modified, meaning that it is not allowed to change it from (int, int).     pragma(msg, typeof(a)); // (int, int) Makes sense

Re: Iterate/sort associative array by value?

2019-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 04/07/2019 08:41 AM, Robert M. Münch wrote: > I have an AA int[ulong] and would like to traverse the AA from biggest > to smallest by value. Is there an elegant way to do this? Because associative array is a data structure to use when the order is not important, it comes down to getting the

Re: Calling D library from other languages on linux using foreign threads

2019-03-23 Thread Ali Çehreli via Digitalmars-d-learn
On 03/22/2019 12:34 PM, tchaloupka wrote: > I've searched a lot at it should be working at least on linux, but > apparently is not or I'm doing something totally wrong.. > > Our use case is to call shared D library from C# (.Net Core) and from > different threads. We needed to do the same from

Re: is collectException working for every exceptions ?

2019-03-19 Thread Ali Çehreli via Digitalmars-d-learn
On 03/19/2019 12:00 AM, Roman Sztergbaum wrote: On Tuesday, 19 March 2019 at 00:07:44 UTC, Ali Çehreli wrote: On 03/18/2019 11:54 AM, Roman Sztergbaum wrote: > [...] with the > [...] Andre Pany has already explained. Otherwise, I was going to say "collectException can collect Exceptions, not

<    5   6   7   8   9   10   11   12   13   14   >